Update data in ListFragment as part of ViewPager

Barkside’s answer works with FragmentPagerAdapter but doesn’t work with FragmentStatePagerAdapter, because it doesn’t set tags on fragments it passes to FragmentManager. With FragmentStatePagerAdapter it seems we can get by, using its instantiateItem(ViewGroup container, int position) call. It returns reference to fragment at position position. If FragmentStatePagerAdapter already holds reference to fragment in question, instantiateItem just … Read more

Proper implementation of ViewPager2 in Android

UPDATE 7 Check : Migrate from ViewPager to ViewPager2 Check : Create swipe views with tabs using ViewPager2 UPDATE 6 Check out my answer if you want to implement Carousel using View Pager2 UPDATE 5 How to use TabLayout with ViewPager2 SAMPLE CODE Use below dependencies implementation ‘com.google.android.material:material:1.1.0-alpha08’ implementation ‘androidx.viewpager2:viewpager2:1.0.0-beta02’ SAMPLE CODE XMl layout <?xml … Read more

Can I use view pager with views (not with fragments)

You need to override these two methods rather than getItem(): @Override public Object instantiateItem(ViewGroup collection, int position) { View v = layoutInflater.inflate(…); … collection.addView(v,0); return v; } @Override public void destroyItem(ViewGroup collection, int position, Object view) { collection.removeView((View) view); }

How to change ViewPager’s page?

I’m not sure that I fully understand the question, but from the title of your question, I’m guessing that what you’re looking for is pager.setCurrentItem( num ). That allows you to programatically switch to another page within the ViewPager. I’d need to see a stack trace from logcat to be more specific if this is … Read more

Is it possible to disable scrolling on a ViewPager

A simple solution is to create your own subclass of ViewPager that has a private boolean flag, isPagingEnabled. Then override the onTouchEvent and onInterceptTouchEvent methods. If isPagingEnabled equals true invoke the super method, otherwise return. public class CustomViewPager extends ViewPager { private boolean isPagingEnabled = true; public CustomViewPager(Context context) { super(context); } public CustomViewPager(Context context, … Read more