title: Send data from fragment to fragment using Tab Layout with Swipeable Views in Android
body: <p>I created a Tab Layout with Swipeable Views.
  I'm trying to pass a string from fragment 
  to Fragment Thank you in Advance
  Details_customer.java</p>
  
  <pre><code>import android.app.ProgressDialog;
  import android.content.Intent;
  import android.content.SharedPreferences;
  import android.net.Uri;
  import android.support.design.widget.TabLayout;
  import android.support.design.widget.FloatingActionButton;
  import android.support.design.widget.Snackbar;
  import android.support.v4.app.FragmentStatePagerAdapter;
  import android.support.v4.view.PagerAdapter;
  import android.support.v7.app.AppCompatActivity;
  import android.support.v7.widget.Toolbar;
  import android.support.v4.app.Fragment;
  import android.support.v4.app.FragmentManager;
  import android.support.v4.app.FragmentPagerAdapter;
  import android.support.v4.view.ViewPager;
  import android.os.Bundle;
  import android.view.LayoutInflater;
  import android.view.Menu;
  import android.view.MenuInflater;
  import android.view.MenuItem;
  import android.view.View;
  import android.view.ViewGroup;
  import android.widget.TextView;
  import android.widget.Toast;
  import com.google.android.gms.appindexing.Action;
  import com.google.android.gms.appindexing.AppIndex;
  import com.google.android.gms.appindexing.Thing;
  import com.google.android.gms.common.api.GoogleApiClient;
  public class Details_customer extends AppCompatActivity implements   Cust_Details_basic.FragmentDataListener {
  SharedPreferences login_pref, IP;
  private ProgressDialog pDialog;//For Loading activity..
  Bundle dataBundle;
  /**
   * The {@link PagerAdapter} that will provide
   * fragments for each of the sections. We use a
   * {@link FragmentPagerAdapter} derivative, which will keep every
   * loaded fragment in memory. If this becomes too memory intensive, it
   * may be best to switch to a
   * {@link FragmentStatePagerAdapter}.
   */
  private SectionsPagerAdapter mSectionsPagerAdapter;
  
  /**
   * The {@link ViewPager} that will host the section contents.
   */
  private ViewPager mViewPager;
  /**
   * ATTENTION: This was auto-generated to implement the App Indexing API.
   * See https://g.co/AppIndexing/AndroidStudio for more information.
   */
  private GoogleApiClient client;
  
  
  
  
  @Override
  protected void onCreate(Bundle savedInstanceState) {
      super.onCreate(savedInstanceState);
      setContentView(R.layout.activity_details_customer);
  
      Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
      setSupportActionBar(toolbar);
      // Create the adapter that will return a fragment for each of the three
      // primary sections of the activity.
      mSectionsPagerAdapter = new SectionsPagerAdapter(getSupportFragmentManager());
  
      // Set up the ViewPager with the sections adapter.
      mViewPager = (ViewPager) findViewById(R.id.container);
      mViewPager.setAdapter(mSectionsPagerAdapter);
  
      TabLayout tabLayout = (TabLayout) findViewById(R.id.tabs);
      tabLayout.setupWithViewPager(mViewPager);
  
      // ATTENTION: This was auto-generated to implement the App Indexing API.
      // See https://g.co/AppIndexing/AndroidStudio for more information.
      client = new GoogleApiClient.Builder(this).addApi(AppIndex.API).build();
  }
  
  
  @Override
  public void onFragmentDataUpdated(Bundle dataBundle)
  {
      this.dataBundle=dataBundle;
  }
  
  
  @Override
  public boolean onCreateOptionsMenu(Menu menu) {
      // Inflate the menu; this adds items to the action bar if it is present.
      MenuInflater inflater = getMenuInflater();
      inflater.inflate(R.menu.menu_main, menu);
      //getMenuInflater().inflate(R.menu.menu_details_customer, menu);
      return true;
  }
  
  @Override
  public boolean onOptionsItemSelected(MenuItem item) {
      switch (item.getItemId()) {
          case R.id.action_logout:
              login_pref = getSharedPreferences("Login Pref", MODE_PRIVATE);
              SharedPreferences.Editor editor = login_pref.edit();
              editor.putString("username", null);
              Intent intent = new Intent(this, MainActivity.class);
              intent.addCategory(Intent.CATEGORY_HOME);
              intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
  
              startActivity(intent);
              Toast.makeText(getApplicationContext(), "Logout", Toast.LENGTH_SHORT).show();
              /*editor.clear();*/
              editor.commit();
              finish();
              break;
      }
      return super.onOptionsItemSelected(item);
  }
  
  /**
   * ATTENTION: This was auto-generated to implement the App Indexing API.
   * See https://g.co/AppIndexing/AndroidStudio for more information.
   */
  public Action getIndexApiAction() {
      Thing object = new Thing.Builder()
              .setName("Details_customer Page") // TODO: Define a title for the content shown.
              // TODO: Make sure this auto-generated URL is correct.
              .setUrl(Uri.parse("http://[ENTER-YOUR-URL-HERE]"))
              .build();
      return new Action.Builder(Action.TYPE_VIEW)
              .setObject(object)
              .setActionStatus(Action.STATUS_TYPE_COMPLETED)
              .build();
  }
  
  @Override
  public void onStart() {
      super.onStart();
  
      // ATTENTION: This was auto-generated to implement the App Indexing API.
      // See https://g.co/AppIndexing/AndroidStudio for more information.
      client.connect();
      AppIndex.AppIndexApi.start(client, getIndexApiAction());
  }
  
  @Override
  public void onStop() {
      super.onStop();
  
      // ATTENTION: This was auto-generated to implement the App Indexing API.
      // See https://g.co/AppIndexing/AndroidStudio for more information.
      AppIndex.AppIndexApi.end(client, getIndexApiAction());
      client.disconnect();
  }
  
  //deleted
  
  /**
   * A {@link FragmentPagerAdapter} that returns a fragment corresponding to
   * one of the sections/tabs/pages.
   */
  public class SectionsPagerAdapter extends FragmentPagerAdapter {
  
      public SectionsPagerAdapter(FragmentManager fm) {
          super(fm);
      }
  
      @Override
      public Fragment getItem(int position) {
          switch (position) {
              case 0:
                  Cust_Details_basic cust_basic = new Cust_Details_basic();
                  cust_basic.setArguments(dataBundle);
                  return cust_basic;
              case 1:
                  Cust_Details_address address = new Cust_Details_address();
                  address.setArguments(dataBundle);
                  return address;
             /* case 2:
                  Cust_Details_last details_last = new Cust_Details_last();
                  return details_last;*/
          }
          return null;
      }
  
      @Override
      public int getCount() {
          // Show 2 total pages.
          return 2;
      }
  
      /***
       * new addition
       ***/
      public void showFragment(String val) {
          System.out.println(val);
      }
  
      @Override
      public CharSequence getPageTitle(int position) {
          switch (position) {
              case 0:
                  return "Basic Info";
              case 1:
                  return "Address";
             /* case 2:
                  return "Address";*/
          }
          return null;
      }
  }}
  </code></pre>
  
  <p>Cust_Details_basic.java Here is my Edittext i want to send the value to next fragment</p>
  
  <pre><code>public class Cust_Details_basic extends Fragment {
  
  EditText finame;
  private ProgressDialog pDialog;//For Loading activity..
  
  public interface FragmentDataListener{
  
      void onFragmentDataUpdated(Bundle dataBundle);
  
  }
  private FragmentDataListener mFragmentDataListener;
  @Override
  
  public void onAttach( Context context )
  {
      super.onAttach( context );
      mFragmentDataListener=(FragmentDataListener)getActivity();
  }
  
  
  @Override
  public View onCreateView(LayoutInflater inflater, ViewGroup container,
                           Bundle savedInstanceState) {
      View view = inflater.inflate(R.layout.details_customer_1, container, false);
      finame = (EditText)view.findViewById(R.id.fname);
     /**********************************************/
      Bundle bundle = new Bundle();
      bundle.putString("fname",finame.getText().toString());
      mFragmentDataListener.onFragmentDataUpdated(bundle);
       /*********************************************/
      return view;
  }}
  </code></pre>
  
  <p>Here is Cust_Details_address.java here i want Edittext value</p>
  
  <pre><code>public class Cust_Details_address extends Fragment implements View.OnClickListener{
  
  Button btnsubmit;
  String fname,firstname;
  @Override
  public View onCreateView(LayoutInflater inflater, ViewGroup container,
                           Bundle savedInstanceState) {
      View view = inflater.inflate(R.layout.details_customer_2, container, false);
  
  
      Bundle bundle = this.getArguments();
  
              if (bundle != null) {
                  firstname = bundle.getString("fname",fname);
  
                  Toast.makeText(getActivity().getApplicationContext(),"fname:"+firstname,Toast.LENGTH_SHORT).show();
                  Log.d("First Name:","=======&gt;"+firstname);
  
              }
              else{
                  Toast.makeText(getActivity().getApplicationContext(),"Am Empty:",Toast.LENGTH_SHORT).show();
              }
  
  
      btnsubmit = (Button)view.findViewById(R.id.btnsubmit);
      btnsubmit.setOnClickListener(this);
  
      return view;
  }}
  </code></pre>