title: pass data to another fragment by swipe view with tab android studio,not button
body: <p>Is it possible to pass a data from fragment to fragment by swipe?  </p>
  
  <p>There are many articles teaching us how to pass the data from fragment to fragment, but most of the article or questions had implemented OnClickListener in their first fragment, which used to pass value to another fragment.</p>
  
  <p>But my case is pass the data from two fragments without any button click and finally save them in different tables by clicking button in the last fragment. What can I do to achieve this??</p>
  
  <p>The flow is  <code>Information</code> >> <code>WorkForce</code> >><code>WorkDetailsTable</code> and save them to different table by one button click. </p>
  
  <p>I have tried to work it out but I get NULL value in SQLite. I think I have miss out a lot but have no idea. PLEASE help me...I've been stuck at here for more than two days...Thanks</p>
  
  <p><strong>Tab.java</strong></p>
  
  <pre><code>public class Tab extends ActionBarActivity implements ActionBar.TabListener {
      ViewPager Tab;
      TabPagerAdapter TabAdapter;
      ActionBar actionBar;
      public static String name = null;
      public static String subContractors = null;
  
  // will be used for data communication 
  
      public static Force force_bean;;
      public static Info info_bean;
  
  
      public static Force getForce(){
  
          return force_bean;
      }
      public static void setForce(Force force){
  
          force_bean=force;
      }
      public static Info getInfo(){
  
          return info_bean;
      }
      public static void setInfo(Info info){
  
          info_bean=info;
      }
  
  
  
      final Activity mActivity = (Activity) this;
  
      @Override
      protected void onCreate(Bundle savedInstanceState) {
          super.onCreate(savedInstanceState);
          setContentView(R.layout.tab1);
  
  
          info_bean = new Info();
          force_bean = new Force();
  
  
          TabAdapter = new TabPagerAdapter(getSupportFragmentManager());
  
  
          Tab = (ViewPager) findViewById(R.id.pager);
  
          Tab.setOnPageChangeListener(
                  new ViewPager.SimpleOnPageChangeListener() {
                      @Override
                      public void onPageSelected(int position) {
  
                          actionBar = ((AppCompatActivity) mActivity).getSupportActionBar();
                          actionBar.setSelectedNavigationItem(position);
                      }
                  });
  
          Tab.setAdapter(TabAdapter);
  
          actionBar = ((AppCompatActivity) mActivity).getSupportActionBar();
  
  //Enable Tabs on Action Bar 
          actionBar.setNavigationMode(ActionBar.NAVIGATION_MODE_TABS);
  
  
  //Add New Tabs 
          actionBar.addTab(actionBar.newTab().setText("Information").setTabListener(this));
          actionBar.addTab(actionBar.newTab().setText("Work Force").setTabListener(this));
          actionBar.addTab(actionBar.newTab().setText("Work Details").setTabListener(this));
  
      }
  
  
      @Override
      public void onTabSelected(ActionBar.Tab tab, android.support.v4.app.FragmentTransaction ft) {
  
      }
  
      @Override
      public void onTabUnselected(ActionBar.Tab tab, android.support.v4.app.FragmentTransaction ft) {
  
      }
  
      @Override
      public void onTabReselected(ActionBar.Tab tab, android.support.v4.app.FragmentTransaction ft) {
  
      }
  }
  </code></pre>
  
  <p><strong>TabPagerAdapter.java</strong></p>
  
  <pre><code>public class TabPagerAdapter extends FragmentStatePagerAdapter {
          public TabPagerAdapter(FragmentManager fm) {
              super(fm);
          }
         @Override
          public Fragment getItem(int i) {
              switch (i) {
                  case 0:
                      return  Information.newInstance("name");
                  case 1:
                      return WorkForce.newInstance("SubCon");
                  case 2:
                      return WorkDetailsTable.newInstance();
              }
              return null ;
          }
          @Override
          public int getCount() {
              return 3; //No of Tabs you can give your number of tabs
          }
  </code></pre>
  
  <p><strong>Informmation.java</strong></p>
  
  <pre><code>public class Information extends Fragment implements View.OnClickListener {
          private Spinner spinner, spinner2, spinner3;
  
          private static String a;
           public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
              super.onCreate(savedInstanceState);
              View info = inflater.inflate(R.layout.information, container, false);
              dialog = new DateDialog();
              spinner = (Spinner)info.findViewById(R.id.spinner);
              addItemsOnSpinner();
              a= spinner.getSelectedItem().toString();
              return info;
          }
  
       public static Information newInstance(String a)
          {
             Information fragment=new Information();
              Bundle bundle=new Bundle();
              bundle.putString("a",a);
              fragment.setArguments(bundle);
              return fragment;
          }
  
       public void addItemsOnSpinner() {
              List&lt;String&gt; list = new ArrayList&lt;String&gt;();
              list.add("1 ");
              list.add("2");
              ArrayAdapter&lt;String&gt; adapter = new ArrayAdapter&lt;String&gt;(getActivity(), android.R.layout.simple_spinner_dropdown_item, list);
              adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
              spinner.setAdapter(adapter);
  
  
  
          }
  </code></pre>
  
  <p><strong>WorkForce.java</strong></p>
  
  <pre><code>public class WorkForce extends Fragment {
          private static EditText txt1;
          private static String subCon;
          public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
              super.onCreate(savedInstanceState);
              View work = inflater.inflate(R.layout.workforce, container, false);
              txt1 = (EditText) work.findViewById(R.id.editText);
              subCon = txt1.getText().toString();
              return work;
          }
  
          public static WorkForce newInstance(String subCon) {
  
              WorkForce f = new WorkForce();
              Bundle bundle = new Bundle();
              bundle.putString("subCon", subCon);
              f.setArguments(bundle);
              return f;
          }
      }
  </code></pre>
  
  <p><strong>WorkDetails.java</strong></p>
  
  <pre><code> private com.example.project.project.API.InfoAPI ts;
       private com.example.project.project.API.WorkDetailsAPI WD;
       private com.example.project.project.API.WorkForceAPI WF;
       public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
       super.onCreate(savedInstanceState);
       View workDetails = inflater.inflate(R.layout.tableworkdetails, container, false);
                  getActivity().setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE);
          spinnerTra = (Spinner) workDetails.findViewById(R.id.spinner6);
          addItemsOnSpinner();
          Button btn1 = (Button)workDetails.findViewById(R.id.button2);
          WD = new com.example.project.project.API.WorkDetailsAPI(getActivity());
          ts = new com.example.project.project.API.InfoAPI(getActivity());
          WF = new com.example.project.project.API.WorkForceAPI(getActivity());
          a1 = spinnerTra.getSelectedItem().toString();
          Bundle bundle = new Bundle();
          final String name = bundle.getString("a");
          final String subContractors = bundle.getString("subCon");
          btn1.setOnClickListener(new View.OnClickListener() {
              public void onClick(View arg0) {
  
  
  
                   add(name, subContractors);
                  }
              });
  
              return workDetails;
          }
  
       public void  add(String name,String subContractors)
          {
              Toast.makeText(getActivity(),+name+subContractors, Toast.LENGTH_SHORT).show();
  ts.insertTimeSheet(name);
  WF.insertWorkForce(subContractors);
  
          }
  </code></pre>
  
  <p><strong>Note: My case is pass the data from two fragments without any button click and finally save them in different tables by clicking button in the last fragment.</strong></p>