0

I have created swipe view With two tab bars in android. I wonder is it possible to pass the data from the first tab to the second tab and lastly save all data in SQLite by one button click? I know can pass data by using button but does it sounds possible by using swipe view? Thanks :)

Information.java

       public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
            super.onCreate(savedInstanceState);
            spinner = (Spinner)info.findViewById(R.id.spinner);
            return info;
        }

 public void addItemsOnSpinner() {
        List<String> list = new ArrayList<String>();
        list.add("1");
        list.add("2");
        list.add("3");
        ArrayAdapter<String> adapter = new ArrayAdapter<String>(getActivity(), android.R.layout.simple_spinner_dropdown_item, list);
        adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
        spinner.setAdapter(adapter);


    }

WorkDetails.java

    public View onCreateView(LayoutInflater inflater,ViewGroup container,Bundle savedInstanceState) {
            super.onCreate(savedInstanceState);
            View work=inflater.inflate(R.layout.workforce,container,false);
            button = (Button)work.findViewById(R.id.button7);
            txt1 = (EditText)work.findViewById(R.id.editText);
            Button btn1=(Button)getView().findViewById(R.id.button2);
            btn1.setOnClickListener(new View.OnClickListener() {
                public void onClick(View arg0) {
                         // save data
       }
            });

            return workDetails;
        }

Edited

After going through some documentation, I tried to build a simple project. But I get this error:

 Process: com.example.project.project, PID: 2068
    java.lang.NullPointerException: Attempt to invoke virtual method 'java.lang.String java.lang.Object.toString()' on a null object reference
            at com.example.project.project.Information.onCreateView(Information.java:46)
            at android.support.v4.app.Fragment.performCreateView(Fragment.java:1962)
            at android.support.v4.app.FragmentManagerImpl.moveToState(FragmentManager.java:1026)
            at android.support.v4.app.FragmentManagerImpl.moveToState(FragmentManager.java:1207)

Below are my code snippets

 public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
 spinner = (Spinner)info.findViewById(R.id.spinner);
        a= spinner.getSelectedItem().toString();
  Fragment fragment=new Fragment();
        Bundle bundle=new Bundle();
        bundle.putString("a",a);
 fragment.setArguments(bundle);
        return info;
    }

 public void addItemsOnSpinner() {
            List<String> list = new ArrayList<String>();
            list.add("1");
            list.add("2");
            list.add("3");
            ArrayAdapter<String> adapter = new ArrayAdapter<String>(getActivity(), android.R.layout.simple_spinner_dropdown_item, list);
            adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
            spinner.setAdapter(adapter);


        }

WorkDetails.java

  Bundle bundle=this.getArguments();
       final String name=bundle.getString("a");
  Button btn1=(Button)getView().findViewById(R.id.button2);
        btn1.setOnClickListener(new View.OnClickListener() {
           public void onClick(View arg0) {
               W1=txtWork1.getText().toString();
                a1 = spinnerTra.getSelectedItem().toString();
                P1=per1.getText().toString();
                ts.insertTimeSheet(name);
                WD.insertWorkDetails(a1,W1,P1);

            }
        });

        return workDetails;
    }
Hoo
  • 1,806
  • 7
  • 33
  • 66
  • Possible duplicate of [How to pass data between fragments](http://stackoverflow.com/questions/5194548/how-to-pass-data-between-fragments) – Panther Oct 04 '15 at 16:46
  • I prefer this http://stackoverflow.com/questions/7149802/how-to-transfer-some-data-to-another-fragment...thanks – Hoo Oct 04 '15 at 17:15
  • What is your problem? Drag items around and place them in different lists or saving it in sql db? – XxGoliathusxX Oct 04 '15 at 17:24
  • @XxGoliathusxX please see the edited post..Thanks – Hoo Oct 04 '15 at 17:35

1 Answers1

0

This has been asked quite number of times. This is a standard problem and is already addressed in android documentation. Please go through the section http://developer.android.com/training/basics/fragments/communicating.html for better understanding.

Panther
  • 8,938
  • 3
  • 23
  • 34