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
824
votes
27 answers

How to determine when Fragment becomes visible in ViewPager

Problem: Fragment onResume() in ViewPager is fired before the fragment becomes actually visible. For example, I have 2 fragments with ViewPager and FragmentPagerAdapter. The second fragment is only available for authorized users and I need to ask…
4ntoine
  • 19,816
  • 21
  • 96
  • 220
639
votes
43 answers

Why `PagerAdapter::notifyDataSetChanged` is not updating the View?

I'm using the ViewPager from the compatibility library. I have succussfully got it displaying several views which I can page through. However, I'm having a hard time figuring out how to update the ViewPager with a new set of Views. I've tried all…
C0deAttack
  • 24,419
  • 18
  • 73
  • 81
613
votes
27 answers

How do disable paging by swiping with finger in ViewPager but still be able to swipe programmatically?

I have ViewPager and below it I have 10 buttons. By clicking on button, for example #4, the pager goes immediately to page #4 by mPager.setCurrentItem(3);. But, I want to disable the paging by swiping with finger horizontally. Thus, the paging is…
theateist
  • 13,879
  • 17
  • 69
  • 109
567
votes
35 answers

IllegalStateException: Can not perform this action after onSaveInstanceState with ViewPager

I'm getting user reports from my app in the market, delivering the following exception: java.lang.IllegalStateException: Can not perform this action after onSaveInstanceState at…
511
votes
11 answers

ViewPager and fragments — what's the right way to store fragment's state?

Fragments seem to be very nice for separation of UI logic into some modules. But along with ViewPager its lifecycle is still misty to me. So Guru thoughts are badly needed! Edit See dumb solution below ;-) Scope Main activity has a ViewPager with…
404
votes
9 answers

What is the difference between FragmentPagerAdapter and FragmentStatePagerAdapter?

What is the difference between FragmentPagerAdapter and FragmentStatePagerAdapter? About FragmentPagerAdapter Google's guide says: This version of the pager is best for use when there are a handful of typically more static fragments to be paged…
336
votes
21 answers

Update ViewPager dynamically?

I can't update the content in ViewPager. What is the correct usage of methods instantiateItem() and getItem() in FragmentPagerAdapter class? I was using only getItem() to instantiate and return my fragments: @Override public Fragment getItem(int…
User
  • 31,811
  • 40
  • 131
  • 232
307
votes
29 answers

TabLayout tab selection

How should I select a tab in TabLayout programmatically? TabLayout tabLayout = (TabLayout) findViewById(R.id.tabs); tabLayout.setupWithViewPager(viewPager);
278
votes
18 answers

Replace Fragment inside a ViewPager

I'm trying to use Fragment with a ViewPager using the FragmentPagerAdapter. What I'm looking for to achieve is to replace a fragment, positioned on the first page of the ViewPager, with another one. The pager is composed of two pages. The first one…
Noodles
  • 3,263
  • 4
  • 19
  • 22
271
votes
7 answers

viewpager setonpagechangelistener deprecated

Today I'm trying to set ViewPager.setOnPageChangeListener and I've found out that it's deprecated.
Jaydipsinh Zala
  • 16,558
  • 7
  • 41
  • 45
256
votes
23 answers

Retrieve a Fragment from a ViewPager

I'm using a ViewPager together with a FragmentStatePagerAdapter to host three different fragments: [Fragment1] [Fragment2] [Fragment3] When I want to get Fragment1 from the ViewPager in the FragmentActivity. What is the problem, and how do I fix…
Qun Qin
  • 2,622
  • 3
  • 14
  • 8
241
votes
31 answers

Getting the current Fragment instance in the viewpager

Below is my code which has 3 Fragment classes each embedded with each of the 3 tabs on ViewPager. I have a menu option. As shown in the onOptionsItemSelected(), by selecting an option, I need to update the fragment that is currently visible. To…
rick
  • 4,665
  • 10
  • 27
  • 44
211
votes
10 answers

Android ViewPager with bottom dots

I want to add 3 bottom dots to my ViewPager, like this. I use FragmentActivity and support library ViewPager.
197
votes
8 answers

How to implement a ViewPager with different Fragments / Layouts

When I start an activity which implements viewpager, the viewpager created various fragments. I want to use different layouts for each fragment, but the problem is that viewpager shows only two layouts at the max (second layout on all of the…
184
votes
10 answers

How do you create an Android View Pager with a dots indicator?

Probably many of you (as me), have problem with creating ViewPager with bottom dots, like this: How do you create such an Android ViewPager?
RediOne1
  • 10,389
  • 6
  • 25
  • 46
1
2 3
99 100