title: pass data between viewpager on change/swipe fragment
body: <p>im searching for some while to find a solution to send data between fragments not on click any button but only on swipe and/ or click on Bottom nav bar,</p>
  
  <p>So in my case i have a Viewpager and three Fragments in the same Activity. on the first Fragment i have a seekbar that is showing me a progress in a Textview and same on the second fragment. i want to pass each textview integer to two textviews on the third fragment. But this should be done when i swipe to the last fragment. hope you understand what i want to do and can help.</p>
  
  <p>I tried to implement OnPause and OnStop but it does not work. Is there a any other method i can call ? i understand that if i change the view to other fragment there should be a call like onswipe or onchangeview to call the command to send data to the last fragment. </p>
  
  <p>My XML files 
  fragment_holding(for PageOne) has a seekbar and a Textview that is displaying the progress
  fragment_wind(for PageTwo) has a seekbar and a Textview that is displaying the progress
  fragment_answer(for PageTree) has two Textview to diplay the progress of each seekbar</p>
  
  <p><strong>FragmentAdapter</strong> </p>
  
  <pre><code>public class FragmentAdapter extends FragmentPagerAdapter {
  private List&lt;android.support.v4.app.Fragment&gt; Fragment = new ArrayList&lt;&gt;(); //Fragment List
  private List&lt;String&gt; NamePage = new ArrayList&lt;&gt;(); // Fragment Name List
  public FragmentAdapter(FragmentManager manager) {
      super(manager);
  }
  public void add(Fragment Frag, String Title) {
      Fragment.add(Frag);
      NamePage.add(Title);
  }
  @Override
  public Fragment getItem(int position) {
      return Fragment.get(position);
  }
  @Override
  public CharSequence getPageTitle(int position) {
      return NamePage.get(position);
  }
  @Override
  public int getCount() {
      return 3;
  }
  </code></pre>
  
  <p><strong>MainActivity</strong></p>
  
  <pre><code>public class MainActivity extends AppCompatActivity{
  ViewPager viewPager;
  BottomNavigationView navigation;
  
  @Override
  protected void onCreate(Bundle savedInstanceState) {
      super.onCreate(savedInstanceState);
      setContentView(R.layout.activity_main);
      navigation = findViewById(R.id.navigation);
      navigation.setOnNavigationItemSelectedListener(mOnNavigationItemSelectedListener);
      viewPager = findViewById(R.id.viewpager); //Init Viewpager
      setupFm(getSupportFragmentManager(), viewPager); //Setup Fragment
      viewPager.setCurrentItem(0); //Set Currrent Item When Activity Start
      viewPager.setOnPageChangeListener(new PageChange()); //Listeners For Viewpager When Page Changed
  
  
  
  }
  public static void setupFm(FragmentManager fragmentManager, ViewPager viewPager){
      FragmentAdapter Adapter = new FragmentAdapter(fragmentManager);
      //Add All Fragment To List
      Adapter.add(new PageOne(), "Page One");
      Adapter.add(new PageTwo(), "Page Two");
      Adapter.add(new PageTree(), "Page Three");
      viewPager.setAdapter(Adapter);
  }
  private BottomNavigationView.OnNavigationItemSelectedListener mOnNavigationItemSelectedListener
          = new BottomNavigationView.OnNavigationItemSelectedListener() {
      @Override
      public boolean onNavigationItemSelected(@NonNull MenuItem item) {
          switch (item.getItemId()) {
              case R.id.navigation_home:
                  viewPager.setCurrentItem(0);
                  return true;
              case R.id.navigation_dashboard:
                  viewPager.setCurrentItem(1);
                  return true;
              case R.id.navigation_notifications:
                  viewPager.setCurrentItem(2);
                  return true;
          }
          return false;
      }
  };
  public class PageChange implements ViewPager.OnPageChangeListener {
      @Override
      public void onPageScrolled(int position, float positionOffset, int positionOffsetPixels) {
      }
      @Override
      public void onPageSelected(int position) {
          switch (position) {
              case 0:
                  navigation.setSelectedItemId(R.id.navigation_home);
                  break;
              case 1:
                  navigation.setSelectedItemId(R.id.navigation_dashboard);
                  break;
              case 2:
                  navigation.setSelectedItemId(R.id.navigation_notifications);
                  break;
          }
      }
      @Override
      public void onPageScrollStateChanged(int state) {
      }
  }
  </code></pre>
  
  <p><strong>PageOne</strong>
  public class PageOne extends Fragment {</p>
  
  <pre><code>private SeekBar sbar;
  private TextView tView;
  
  @Nullable
  @Override
  public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup container, Bundle savedInstanceState) {
      @SuppressLint("InflateParams") View view = inflater.inflate(R.layout.fragment_holding, null);
      sbar =(SeekBar) view.findViewById(R.id.seekBar5);
      tView = (TextView) view.findViewById(R.id.textView6);
      tView.setText(sbar.getProgress() + "/" + sbar.getMax());
  
  
      sbar.setOnSeekBarChangeListener(new SeekBar.OnSeekBarChangeListener() {
          int pval = 0;
          @Override
          public void onProgressChanged(SeekBar seekBar, int progress, boolean fromUser) {
              pval = progress;
              tView.setText(pval + "/" + seekBar.getMax());
  
  
  
  
          }
          @Override
          public void onStartTrackingTouch(SeekBar seekBar) {
              //write custom code to on start progress
          }
          @Override
          public void onStopTrackingTouch(SeekBar seekBar) {
          }
      });
      return view;
  }
  </code></pre>
  
  <p><strong>PageTwo</strong></p>
  
  <pre><code>public class PageTwo extends Fragment {
  
  private SeekBar sbar4;
  private TextView tView4;
  
  
  @Nullable
  @Override
  public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup container, Bundle savedInstanceState) {
      @SuppressLint("InflateParams") View view = inflater.inflate(R.layout.fragment_wind, null);
  
  
  
      sbar4 =(SeekBar) view.findViewById(R.id.seekBar5);
      tView4 = (TextView) view.findViewById(R.id.textView6);
      tView4.setText(sbar4.getProgress() + "/" + sbar4.getMax());
  
  
      sbar4.setOnSeekBarChangeListener(new SeekBar.OnSeekBarChangeListener() {
          int pval = 0;
  
          @Override
          public void onProgressChanged(SeekBar seekBar, int progress, boolean fromUser) {
              pval = progress;
              tView4.setText(pval + "/" + seekBar.getMax());
  
          }
          @Override
          public void onStartTrackingTouch(SeekBar seekBar) {
              //write custom code to on start progress
          }
          @Override
          public void onStopTrackingTouch(SeekBar seekBar) {
          }
      });
      return view;
  }
  </code></pre>
  
  <p><strong>PageTree</strong></p>
  
  <p>public class PageTree extends Fragment {</p>
  
  <pre><code>@Nullable
  @Override
  public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
      View view = inflater.inflate(R.layout.fragment_answer, container, false);
  
  
  
  
  
      return view;
  }
  </code></pre>