1

I have a ViewPager with PagerTabStrip and three tabs,lets say "1","2","3" and the situation is this:

1*When first tab is selected,the visible selection is this:

1 2-the selector is under 1,tab 1 and tab 2 are visible

2*But when I select the second tab,the result is this :

1 2 3 -the selector is under 2,all tabs are visible(this is what i want)

3* When I have selected the third tab : 2 3 -the selector is under 3,tab 2 and 3 are visible

So I want when whichever tab is selected - all tabs to be visible(like 2*).So what is needed to do that?If you need the source code I could provide it,but it seems that this can be fixed with some property of the ViewPager or just to use another control?I just want to see all tabs and to choose from them,not to move from 1 to 2 and then to see 3...

So it seems that it can`t be solve this with setting the argument to zero : ViewPager.setOffscreenPageLimit(0) doesn't work as expected Any idea?

Community
  • 1
  • 1
  • I guess you have to show some code, it seems you are doing something wrong. In a viewpager one tab belongs to one view and vice versa. – ElDuderino Jun 03 '14 at 14:05
  • If you don't need the animated movement between tabs, then you don't need a ViewPager. Just use a FrameLayout as a container, and swap the Tabs manually in a TabListener – LordRaydenMK Jun 03 '14 at 14:23

2 Answers2

1

ViewPager gets rid of views that are not in focus. When you select the tab 3, tab 1 is away because of this, and when you select 1, the same happens to 3.

There is a property as you say:

viewPager.setOffscreenPageLimit(int limit)

See this for more info: http://developer.android.com/intl/es/reference/android/support/v4/view/ViewPager.html

Be carefull on keep all views, because ViewPager does this to save memory.

Good luck.

Alberto
  • 367
  • 3
  • 11
  • I have tried this : mViewPager = (CustomViewPager) findViewById(R.id.pager); mViewPager.setAdapter(new SampleFragmentPagerAdapter()); mViewPager.setOffscreenPageLimit(3); and it doesn`t works...I tried it with argument 0 too..... – user3703313 Jun 03 '14 at 14:01
  • Mmmmm that's weird, it works for me... Maybe call it before setting the adapter? I don't know why is not working. – Alberto Jun 03 '14 at 14:10
  • 1
    Yes,I have tried it before and after setting the adapter,here is the reason why it doesn`t works with argument zero : http://stackoverflow.com/questions/10073214/viewpager-setoffscreenpagelimit0-doesnt-work-as-expected – user3703313 Jun 03 '14 at 14:17
0

After this suggestion : If you don't need the animated movement between tabs, then you don't need a ViewPager. Just use a FrameLayout as a container, and swap the Tabs manually in a TabListener – I have decided to use Fragments and I added ActionBar.Tab for each fragment with TabListener.And everything works fine for now. Thaks to everybody!