Nasim
Nasim

Reputation: 125

Load Detailed Data On Viewpager

I am a beginner at android. I have made a viewpager with two fragments. I have some recycler view item in the first fragment. One recyclerview item will fill a fragment. on swipe to next fragment can I load the details of the recycler view item which i have swiped. or how to pass the position of the recyclerview item to next fragment on swipe please help.

Upvotes: 1

Views: 49

Answers (1)

Ali Samawi
Ali Samawi

Reputation: 1099

well you can do this solution:

  • first you should send data from your first fragment to your activity: to send data to your activity you can implement an interface inside your activity and call it inside the fragment when you want to pass data: Android Passing Data Between Fragments
  • second you should send the data from activity to your second fragment when user swiped the viewpager: you can implement an interface inside your second fragment and call it inside of onPageSelected function :

    viewPager.addOnPageChangeListener(new OnPageChangeListener() {
      public void onPageScrollStateChanged(int state) {}
      public void onPageScrolled(int position, float positionOffset, int 
      positionOffsetPixels) {}
    
       public void onPageSelected(int position) {
       // Check if this is the page you want.
       }
    });
    

Upvotes: 1

Related Questions