Questions tagged [android-viewpager2]

ViewPager2 is the replacement of ViewPager, addressing most of its predecessor's pain-points, including right-to-left layout support, vertical orientation and modifiable Fragment collections.

New features

  • Comparing to its predecessor android.support.v4.view.ViewPager (VP1):
  • Right-to-left (RTL) layout support
  • Vertical orientation support
  • notifyDataSetChanged fully functional (VP1 bugs addressed)

API changes

  • FragmentStateAdapter replaces FragmentStatePagerAdapter
  • RecyclerView.Adapter replaces PagerAdapter
  • registerOnPageChangeCallback replaces addPageChangeListener

Known issues

  • clipToPadding
  • no fakeDrag
  • JavaDoc
  • nested scrolling parallel to orientation
  • no offscreen limit control
  • needs better TabLayout integration
  • no pageWidth setter (forced 100%/100%)
  • page transformer: no hardware/software layer choice; no reverse drawing order
  • keep current item visible when inserting a page before current
  • keyboard navigation needs work
  • FragmentStateAdapter stability / performance improvements coming

Useful links:

Official documentation

Official sample

Fundamental Stack Overflow answer

740 questions
0
votes
0 answers

ViewPager2 is not able to get the current visible item view holder correctly

So just to elaborate on the problem. I am trying to auto scroll to the next item after a certain interval. If i swipe manually the viewpager2 retrieves the itemview correctly. But when i do it in auto mode .It is not able to get the current visible…
0
votes
0 answers

Touch listener not working in RecyclerView + ViewPager2

My current layout has a CoordinatorLayout, in which I've a TabLayout connected to a ViewPager2. Within ViewPager, I have a couple of tabs of RecyclerView.
0
votes
1 answer

Viewpager must not be null (Viewpager2)

I'm trying to implement viewpager when press of a button on secondary activity for that I created a PageAdaper class which extends Recycler view.Adapter .I got viewpager must not be null error on runtime . PageAdaper.kt open class…
Ajith Selvan
  • 45
  • 1
  • 9
0
votes
0 answers

How to set adapter for viewPager2

I have been trying to set gallery like view so I created a class which extends PagerAdapter as like in the link. I followed this But my problem is I can't setAdapter to viewPager as it asks RecycleView.Adapter as type but…
Ajith Selvan
  • 45
  • 1
  • 9
0
votes
1 answer

Don't save fragment state in ViewPager2

I am using ViewPager2 with FragmentStateAdapter and if I have three fragments the default behavior is to save fragment state, actually I have one fragment but create instances and pass different types to it, so if I have Fragment A, A1 and A2 and I…
Karim Ata
  • 343
  • 6
  • 15
0
votes
2 answers

Viewpager2 + RecyclerView Scroll Issue

I have a viewpager2 with TabLayout which hosts fragments that contain a vertical RecyclerView as shown in the GIF Sometimes when I scroll to top or bottom the ViewPager swipe occurs and changes tab. I wrapped my RecyclerView inside…
0
votes
1 answer

Pin tablayout in Scrollview with appbarlayout

My android app want to have a page like Facebook page which pin the tablayout on top of the screen when scroll below the tablayout. I have found a few answers on this topic. pin TabLayout to top and below the toolbar Scrollview How to make tablayout…
0
votes
2 answers

can't get ScrollView from ViewPager2 in OnPageChangeCallBack

I have a ViewPager2 contains ScrollView. What the problem is, when I try to get ScrollView of current page in onPageSelected(), it doesn't work. Here I'd like to set previous scrollY to the ScrollView when user back to see selected page. (because…
ntsrng
  • 3
  • 4
0
votes
1 answer

Is it possible to implement a ViewPager2 inside another ViewPager2?

The layout I'm currently using consists of a TabLayout with Viewpager2, what I'm trying to achieve is implementing another ViewPager2 to display several images in one of the tabs. But the issue I'm facing is when I swipe, I am only able to switch…
Noxagon
  • 15
  • 6
0
votes
1 answer

Clear data of fragments in ViewPager with each swipe

@Override public void onViewDetachedFromWindow(@NonNull FragmentViewHolder holder) { super.onViewDetachedFromWindow(holder); } I have many independent EditText with different id in each fragments of viewpager. For each swipe I want to clear…
0
votes
1 answer

How to update view inside the viewpager2 that attach to fragment on fragment onResume?

I have a fragment "Fragment List" that contains Viewpager2. When user clicks a button "Fragment List" will be replaced with "Fragment Form", after user finish updating the form. I will pop backstack the "Fragment Form". And the OnResume of "Fragment…
Hal. ss
  • 63
  • 1
  • 11
0
votes
1 answer

Android navigation with activity and PagerView2

I have an issue with my Android app that uses Navigation and ViewPager2. I've the main Activity which implements a Navigation Drawer and has its own Navigation Graph and it works fine with the rest of the application. Then I have a second Activity…
Sergiob
  • 838
  • 1
  • 13
  • 28
0
votes
1 answer

ViewPager2 fragment content is disappear when focus on EditText

when i focus on EditText by click in that, the content of viewpager2 is disappear an when i start typing content is reappear and also when rotate my phone content reappear you can see issue in video here this is my class for create tablayout and…
0
votes
1 answer

How to know primary fragment item of FragmentStateAdapter

I have a view pager type FragmentStateAdapter and would like to know when the primary fragment is in position e.g. 100% visible. Does FragmentStateAdapter even support this? I've already tried approaches on this post with no luck. Each fragment in…