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
182
votes
3 answers

Android.app Fragments vs. android.support.v4.app using ViewPager?

I have a question regarding the Android Support Libraries, Fragments, and as a specific example, the ViewPager class. My intention is to create an app with similar functionality to the sample provided on the Android Developer website…
171
votes
5 answers

Determine when a ViewPager changes pages

I have three pages (Fragments) inside a ViewPager, however I only want to display a menu item for two of those pages. The code given in a previous SO answer does not seem to work: @Override public void setUserVisibleHint(boolean isVisibleToUser) { …
arjs
  • 2,835
  • 4
  • 22
  • 18
166
votes
8 answers

dynamically add and remove view to viewpager

(I figured out a solution - please see my post in the Answer section below.) In my app, the user will start with a single view of his data. I'd like to add a ViewPager and allow the user to add more views as desired. How do I do this? (I dont'…
Peri Hartman
  • 19,314
  • 18
  • 55
  • 101
154
votes
16 answers

Is it possible to disable scrolling on a ViewPager

I have a ViewPager which instantiates a View. I'd like to disable both the scrolling of the viewpager and the child buttons momentarily while a search result is returned to the view. I've calling viewPager.setEnabled(false) but this doesn't disable…
mAndroid
  • 5,087
  • 6
  • 25
  • 33
151
votes
5 answers

How to change ViewPager's page?

I'm using ViewPager in my app and define it in the main Activity. Inside onCreate method I load some number of pages from SharedPreferences and then pass it to PagerAdapter: @Override public int getCount() { return numberOfPages; } The problem…
Roman
  • 5,358
  • 9
  • 34
  • 43
150
votes
9 answers

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

I am using ViewPager for swiping between Fragments, but can I use ViewPager to swipe between Views simple XML layout? This is my page Adapter for the ViewPager which is used to swipe between Fragments: import java.util.List; import…
ranjith
  • 4,526
  • 5
  • 27
  • 31
150
votes
8 answers

ViewPager with previous and next page boundaries

I'm designing a view with multiple pages. I want edges of previous and next pages to be show like below and implement a 2 finger swipe to switch between pages. I tried using ViewPager with negative page margin as suggested here but that only shows…
Gaurav Arora
  • 17,124
  • 5
  • 33
  • 44
149
votes
13 answers

Proper implementation of ViewPager2 in Android

I came to know about ViewPager2 and tried to implement it, but didn't find any proper example. Can anyone tell me how can I use it. I am looking for proper usage, not an example.
Pratik Butani
  • 60,504
  • 58
  • 273
  • 437
148
votes
17 answers

Android ViewPager - Show preview of page on left and right

I'm using Android's ViewPager. What I want to do is to show a preview of the page on both the left and the right. I've seen where I can use a negative pageMargin to show a preview of the right side. setPageMargin(-100); Is there anyway that I can…
Brian Boyle
  • 2,849
  • 5
  • 27
  • 35
144
votes
17 answers

Remove Fragment Page from ViewPager in Android

I'm trying to dynamically add and remove Fragments from a ViewPager, adding works without any problems, but removing doesn't work as expected. Everytime I want to remove the current item, the last one gets removed. I also tried to use an…
astuetz
  • 2,693
  • 2
  • 23
  • 22
141
votes
10 answers

Update data in ListFragment as part of ViewPager

I'm using the v4 compatibility ViewPager in Android. My FragmentActivity has a bunch of data which is to be displayed in different ways on different pages in my ViewPager. So far I just have 3 instances of the same ListFragment, but in the future…
137
votes
4 answers

Prevent ViewPager from destroying off-screen views

I have a ViewPager hooked up to a FragmentPagerAdapter that's displaying three fragments. The ViewPager appears to destroy a hosted fragment's view when it is more than one swipe away from the current position. These views are all simple lists and…
chefgon
  • 1,931
  • 4
  • 17
  • 17
136
votes
14 answers

Android: Vertical ViewPager

Is there a way to make a ViewPager that does not scroll horizontally, but vertically?!
user1709805
  • 2,028
  • 3
  • 19
  • 26
131
votes
3 answers

How to force ViewPager to re-instantiate its items

I am using ViewPager to allow user to swipe between its views. Is there a way how to force this ViewPager to reload/re-instantiate its views in case that they are no longer valid or needs to be refreshed? I tried to call notifyDataSetChanged() on…
gordonfreeman
  • 2,485
  • 2
  • 16
  • 13
123
votes
21 answers

ViewPager in a NestedScrollView

I need to create an interface like Google Newsstand which is a sort of ViewPager (horizontal scroll) over a collapsing header (vertical scroll). One of my requirements is to use the new Design Support Library presented at the Google IO…