SetCurrentItem For ViewPager In Nested Fragment From RecylerviewAdapter
I have a parent activity (NavigationActivity) that has a viewPager with four fragments(frag1, frag2, frag3, frag4). Then frag2 has a nestedViewPager with 3 fragments(nestedFrag1,
Solution 1:
I think it really depends on what your app is and what responsabilities your classes have...
I might implement an interface like ImageClickResolver on frag2 with a changePageForImage method then send this reference to newstedViewPager->nestedFrag1->adapter. So adapter has someone to call that is able to decide according to the image. Or just use Otto or an event bus so you emits an event when the image was posted and have frag2 listen to it.
Solution 2:
I have been able to solve this using the following method:
- In my nested fragment that has the recyclerView (nestedFrag2) I called getParentFragment() and instantiated it as a nestedFrag1 (that holds the viewPager)
- I then set up an interface in my recylerView adapter and implemented the interface in nestedFrag2 and used the callback in the onBindView listener show above.
Post a Comment for "SetCurrentItem For ViewPager In Nested Fragment From RecylerviewAdapter"