Questions tagged [android-viewpager]

ViewPager.setcurrentItem( ) freezes ui

The ViewPager is a widget for Android that makes possible displaying different views (or fragments) side by side allowing the user to swipe between them. ViewPager was released as part of the Compatibility Package revision 3 and works with Android 1.6 upwards. ViewPager is a ViewGroup and works in a similar manner to AdapterViews (like ListView and Gallery).

Official Documentation

10802 questions
116
votes
4 answers

How to programmatically show next view in ViewPager?

I created a ViewPager and everything is working fine, however I want to have a previous next button outside of ViewPager which can be used to navigate inside ViewPager. How can I go to next Item on ViewPager without swiping manually?
Vaibhav Mishra
  • 11,384
  • 12
  • 45
  • 58
112
votes
14 answers

Getting the error "Java.lang.IllegalStateException Activity has been destroyed" when using tabs with ViewPager

I have an application that consists of using ActionBarSherlock in tab mode.I have 5 tabs and the content of each tab is handled using fragments. For tab2 though, I have a fragment the xml file of which holds a ViewPager element which in turn has…
110
votes
8 answers

How to prevent a scrollview from scrolling to a webview after data is loaded?

So I have a fascinating problem. Despite the fact that I'm not manually or programmatically scrolling my view, my WebView is being automatically scrolled to after the data inside it loads. I've got a fragment in a viewpager. When I first load the…
108
votes
13 answers

ViewPager.setOffscreenPageLimit(0) doesn't work as expected

The fragments I use in my ViewPager instance are quite resource intensive, so I'd only like to load one at a time. When I try the following: mViewPager.setOffscreenPageLimit(0); mViewPager.setAdapter(mPagerAdapter); My…
Chris Lacy
  • 4,222
  • 3
  • 35
  • 33
107
votes
8 answers

How do you create a transparent demo screen for an Android app?

I'm trying to create a semi-transparent demo screen that is launched only when a user first installs my application. Here's an example from the Pulse News app: Galaxy Nexus Nexus One Instead of a 'tap-to-dismiss' feature, I want the user to be…
Gautam
  • 4,006
  • 3
  • 32
  • 37
105
votes
7 answers

FragmentPagerAdapter deprecated

Since API 27 FragmentPagerAdapter is deprecated. What's the best alternative to use for this? In my case, I understand something like super(fragmentManager, BEHAVIOR_RESUME_ONLY_CURRENT_FRAGMENT) would need to be used, but I don't know where within…
wbk727
  • 8,017
  • 12
  • 61
  • 125
104
votes
18 answers

Get current fragment with ViewPager2

I'm migrating my ViewPager to ViewPager2 since the latter is supposed to solve all the problems of the former. Unfortunately, when using it with a FragmentStateAdapter, I don't find any way to get the currently displayed…
guillaume-tgl
  • 2,749
  • 3
  • 23
  • 30
103
votes
15 answers

Fragment in ViewPager using FragmentPagerAdapter is blank the second time it is viewed

I have a fragment interface with tabs along the bottom which open different fragments in the main view. I have one particular fragment which is a list of items. If the user selects one of the items in this list, another fragment opens which…
99
votes
9 answers

SwipeRefreshLayout + ViewPager, limit horizontal scroll only?

I've implemented SwipeRefreshLayout and ViewPager in my app but there is a big trouble: whenever I'm going to swipe left / right to switch between pages the scrolling is too sensitive. A little swipe down will trigger the SwipeRefreshLayout refresh…
user3896501
  • 2,987
  • 1
  • 22
  • 25
95
votes
9 answers

ViewPager with Google Maps API v2: mysterious black view

I have integrated the new google maps api v2 fragment in a view pager. When scrolling from the map fragment, a black view overlaps the adjacent fragments. Someone has solved? Edit: screenshot public static class PagerAdapter extends…
Pepe
  • 953
  • 1
  • 7
  • 6
91
votes
9 answers

ViewPager inside a ScrollView does not scroll correclty

I have a 'page' that has a number of components on it, and who's content is longer than the height of the device. Fine, just put all of the layout (the entire page) inside a ScrollView, no problem. One of the components is a ViewPager. This…
electricSunny
  • 3,229
  • 4
  • 19
  • 21
90
votes
13 answers

ViewPager does not redraw content, remains/turns blank

We're suffering from a very strange issue with ViewPager here. We embed lists on each ViewPager page, and trigger notifyDataSetChanged both on the list adapter and the view pager adapter when updating list data. What we observe is that sometimes,…
mxk
  • 43,056
  • 28
  • 105
  • 132
87
votes
5 answers

Getting the current position of a ViewPager

I know with the Gallery widget I was able to use getSelectedItemPosition(); to retrieve the current position, however it doesnt seem ViewPager has that. I know I can setup a listener and retrieve the position when the page is switched. But I want…
Adam
  • 8,849
  • 16
  • 67
  • 131
87
votes
8 answers

How do you get the current page number of a ViewPager for Android?

I want to know the current page position of the ViewPager. I create an adapter and set this adapter to the ViewPager. Now I want to know the current page number or position of the current view, because I want to start some extra events on that…
sam_k
  • 5,983
  • 14
  • 76
  • 110
87
votes
10 answers

How to disable behind view click event Framelayout

Here i have one view pager activity which has one imageview and 2 overlay bars. there overlay bars i made using android xml file layout itself. Here my requirement is like that 1) single tap on view pager's imageview first time = show top and…