title: Android - Pass "edit text" element value between tabbed fragments
body: <p>I have an activity with multiple swipe tabbed fragments. Each fragment has some check-boxes, edit text and switch fields. What I want is to navigate through all the tabs, edit the state of the fields then on last tab to collate the information within all the elements and save these details into a database.</p>
  
  <p>My problem is that I don't know how to save these elements values and pass them to my last tab in order to be stored.</p>
  
  <p>I am quite a newbie with Android apps so any hint or answer would be very much appreciated.</p>
  
  <p>Here is how code looks so far:</p>
  
  <p><strong>Activity:</strong></p>
  
  <pre><code>public class IconTextTabsActivity extends AppCompatActivity {
  
  private Toolbar toolbar;
  private TabLayout tabLayout;
  private ViewPager viewPager;
  private int[] tabIcons = {
          R.drawable.ic_tab_favourite,
          R.drawable.ic_tab_call,
          R.drawable.ic_tab_contacts,
          R.drawable.ic_vector_test
  };
  
  
  @Override
  protected void onCreate(Bundle savedInstanceState) {
      super.onCreate(savedInstanceState);
      setContentView(R.layout.activity_icon_text_tabs);
  
      toolbar = (Toolbar) findViewById(R.id.toolbar);
      setSupportActionBar(toolbar);
      getSupportActionBar().setDisplayHomeAsUpEnabled(true);
  
      viewPager = (ViewPager) findViewById(R.id.viewpager);
      setupViewPager(viewPager);
  
      tabLayout = (TabLayout) findViewById(R.id.tabs);
      tabLayout.setupWithViewPager(viewPager);
      setupTabIcons();
  
      Bundle b = getIntent().getExtras();
      String id = b.getString("id");
  
      Toast.makeText(this, id, Toast.LENGTH_LONG).show();
  
  }
  
  private void setupTabIcons() {
      tabLayout.getTabAt(0).setIcon(tabIcons[0]);
      tabLayout.getTabAt(1).setIcon(tabIcons[1]);
      tabLayout.getTabAt(2).setIcon(tabIcons[2]);
      tabLayout.getTabAt(3).setIcon(tabIcons[2]);
      tabLayout.getTabAt(4).setIcon(tabIcons[3]);
  }
  
  private void setupViewPager(ViewPager viewPager) {
      ViewPagerAdapter adapter = new ViewPagerAdapter(getSupportFragmentManager());
      adapter.addFrag(new OneFragment(), "ONE");
      adapter.addFrag(new TwoFragment(), "TWO");
      adapter.addFrag(new ThreeFragment(), "THREE");
      adapter.addFrag(new FourFragment(), "FOUR");
      adapter.addFrag(new FiveFragment(), "FIVE");
      viewPager.setAdapter(adapter);
  }
  
  @Override
  public boolean onSupportNavigateUp() {
      onBackPressed();
      return true;
  }
  
  
  @Override
  public void onBackPressed() {
      super.onBackPressed();
      overridePendingTransition(R.anim.left_to_right, R.anim.right_to_left);
  }
  
  class ViewPagerAdapter extends FragmentPagerAdapter {
      private final List&lt;Fragment&gt; mFragmentList = new ArrayList&lt;&gt;();
      private final List&lt;String&gt; mFragmentTitleList = new ArrayList&lt;&gt;();
  
      public ViewPagerAdapter(FragmentManager manager) {
          super(manager);
      }
  
      @Override
      public Fragment getItem(int position) {
          return mFragmentList.get(position);
      }
  
      @Override
      public int getCount() {
          return mFragmentList.size();
      }
  
      public void addFrag(Fragment fragment, String title) {
          mFragmentList.add(fragment);
          mFragmentTitleList.add(title);
      }
  
      @Override
      public CharSequence getPageTitle(int position) {
          return mFragmentTitleList.get(position);
      }
  }
  </code></pre>
  
  <p><strong>Tab Fragment 1</strong></p>
  
  <pre><code>public class OneFragment extends Fragment {
  
  private EditText mBreedName;
  
  public OneFragment() {
      // Required empty public constructor
  }
  
  @Override
  public void onCreate(Bundle savedInstanceState) {
      super.onCreate(savedInstanceState);
  }
  
  @Override
  public View onCreateView(LayoutInflater inflater, ViewGroup container,
                           Bundle savedInstanceState) {
      // Inflate the layout for this fragment
      View v = inflater.inflate(R.layout.fragment_one, container, false);
  
      mBreedName = (EditText) v.findViewById(R.id.addName);
  
      return v;
  }
  </code></pre>
  
  <p><strong>Tab Fragment 2</strong></p>
  
  <pre><code>public class TwoFragment extends Fragment {
  
  public TwoFragment() {
      // Required empty public constructor
  }
  
  @Override
  public void onCreate(Bundle savedInstanceState) {
      super.onCreate(savedInstanceState);
  }
  
  @Override
  public View onCreateView(LayoutInflater inflater, ViewGroup container,
                           Bundle savedInstanceState) {
  
      // Inflate the layout for this fragment
      View v = inflater.inflate(R.layout.fragment_two, container, false);
  
      return v;
  }
  </code></pre>
  
  <p>Assuming that Tab Fragment 2 is my last tab, how could I retrieve here the text value for "mBreedName" stored into Tab Fragment 1?</p>
  
  <p>Thanks!</p>