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
83
votes
9 answers

How to disable or enable viewpager swiping in android

What i am trying to do: I am trying to Enable/disable swiping in pager programatically when the program is running Ex: When on the flow if i check for a condition and if it returns true enable swiping, and if condition returns false disable…
Devrath
  • 42,072
  • 54
  • 195
  • 297
79
votes
9 answers

PagerAdapter start position

I'm using the following example to impliment my viewPager: http://code.google.com/p/viewpagerexample/issues/list The problem with this example is that I can't figure out how to set my starting position, the default starting position is 0. Basically…
Kirill Kulakov
  • 10,035
  • 9
  • 50
  • 67
77
votes
12 answers

android.content.res.Resources$NotFoundException: Unable to find resource ID #0xffffffff

I hate posting code, and asking why it doesn't work, but I'm at a loss right now. I've tried to run the following class below, and I get an exception in logcat which I can't explain. Even a google search yields little results. Maybe I just don't…
Vijay Sharma
  • 2,252
  • 1
  • 17
  • 21
75
votes
18 answers

Android ViewPager get the current View

I have a ViewPager, and I'd like to get the current selected and visible view, not a position. getChildAt(getCurrentItem) returns wrong View This works not all the time. Sometimes returns null, sometimes just returns wrong View. @Override public…
lacas
  • 13,928
  • 30
  • 109
  • 183
75
votes
7 answers

Change ViewPager animation duration when sliding programmatically

I'm changing slide with the following code: viewPager.setCurrentItem(index++, true); But it changes too fast. Is there a way to set manually the animation speed?
User
  • 31,811
  • 40
  • 131
  • 232
74
votes
10 answers

How to test if a fragment view is visible to the user?

I have a ViewPager, each page is a Fragment view. I want to test if a fragment is in a visible region. the Fragment.isVisible only test the fragment is attached to a activity the fragment is set to visible the fragment has been added to a view The…
David S.
  • 10,578
  • 12
  • 62
  • 104
72
votes
5 answers

Disabling animation in ViewPager

I'd like to disable all the animations for the transitions in my custom ViewPager. This view pager contains four tabs -and each tab loads a Fragment- and what the view pager does is to switch the tabs: for example first tab is the index, second is…
noloman
  • 11,411
  • 20
  • 82
  • 129
71
votes
5 answers

ViewPager's Fragment's view lost when ViewPager's parent Fragment hidden then shown

I've been seeing some strange behavior with my ViewPager along with my own FragmentStatePagerAdapter. My View hierarchy goes like this: -> (1) Fragment root view (RelativeLayout) -> (2) ViewPager -> (3) ViewPager's current fragment view When the…
John Leehey
  • 22,052
  • 8
  • 61
  • 88
70
votes
11 answers

Is it possible to access the current Fragment being viewed by a ViewPager?

I have an app with a ViewPager and three Fragments. I'm trying to figure out how to get the current Fragment being viewed so I can get at its arguments. I have an OnPageChangeListener grabbing the current page index, but ViewPager.getChildAt(int…
MitchellSalad
  • 4,171
  • 8
  • 23
  • 24
69
votes
5 answers

Set default page for ViewPager in Android

I am using the following code, MAX is 2 pages. By default the position is 0 and adds a new page to the right. I inflate two layout files. How can I show the page1 when the app starts and add a new page to the left ? Thanks. main.xml
dcanh121
  • 4,665
  • 11
  • 37
  • 84
69
votes
10 answers

onPageSelected isn't triggered when calling setCurrentItem(0)

I have an Activity with a ViewPager which displays a bunch of pictures. When it starts the ViewPager's position is set based on what the user selected in a previous Activity. Similar to a gallery. I want the onPageSelected to be called every time a…
jpihl
  • 7,941
  • 3
  • 37
  • 50
65
votes
1 answer

Detect ViewPager tab change inside Fragment

I have a ViewPager with multiple fragments. In one Fragment I play audio. When I swipe to another fragment I want to stop the audio playback. How do I detect that the another fragment is now visible in the ViewPager? I've tried overriding onStop and…
l33t
  • 18,692
  • 16
  • 103
  • 180
65
votes
7 answers

Android ViewPager padding/margin between page fragments

Android Market/Google Music seem to be able to have a gap of some sort between the different fragments that are contained in the ViewPager. Any idea how this is done? Adding margin/padding to the actual fragment view doesn't work, because the view…
psychotik
  • 38,153
  • 34
  • 100
  • 135
64
votes
14 answers

ViewPager as a circular queue / wrapping

I am using a ViewPager with the FragmentStatePagerAdapter to allow navigation between some fragments. Let's say I have three fragments: A, B and C. The ViewPager shows Fragment A initially, and allows you to navigate to Fragment B by swiping from…
antonyt
  • 21,863
  • 9
  • 71
  • 70
63
votes
15 answers

Update Fragment from ViewPager

I have an Activity with a ViewPager. I also have a Dialog that will retrieve a list with some items that the user will choose. Now, how can I update the Fragment where the Items are supposed to display as new views attached to this Fragment? Here…
Luis Lavieri
  • 4,064
  • 6
  • 39
  • 69