Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Two fragments in one viewpager page

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!

like image 960
henry74918 Avatar asked Nov 01 '12 10:11

henry74918


People also ask

How do you get ViewPager fragments?

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.

How does ViewPager2 work?

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.

How to set ViewPager in Android?

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 .


1 Answers

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

like image 135
henry74918 Avatar answered Sep 21 '22 23:09

henry74918