Currently, I use one fragment per viewpager's page through FragmentPagerAdapter very well. But now I want to use a two panel view inside one viewpager's page for tablet. Fro example, the left hand side is a list view and the right hand side is a gridview. Does anybody know How can I achieve that? Thanks a lot!
ViewPager save Fragment in FragmentManager with particular tags, So We can get ViewPager's fragment by FragmentManager class by providing tag. And ViewPager provide tag to each fragment by following syntax : Fragment page = getSupportFragmentManager(). findFragmentByTag("android:switcher:" + R.
So a Viewpager is an android widget that is used to navigate from one page to another page by swiping left or right using the same activity. So when we use Viewpager, we can add different layouts in one activity and this can be done by using the fragments.
To use ViewPager and tabs, you need to add a dependency on ViewPager and on Material Components to your project. To insert child views that represent each page, you need to hook this layout to a PagerAdapter .
Finally I use two view in one fragment and control the data myself. But I noticed There is a new feature in support package and framework so that I can add a fragment inside fragment. See Answer here: Fragment Inside Fragment
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With