ViewPager number of visible tabs - android

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?

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.

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!

Related

Viewpager , How to switch the current page to another page which is not included in the ViewPager , with keeping the Tablayout at the bottom

First , Sorry for my vague title ,
I really don't know how to describe the problem I met.
I will try to draw a picture to explain.
In the following picture , there is a ViewPager with a TabLayout pointing to the first page.
so it works like this :
And the problem is , How to switch the current page to another page which is not included in the ViewPager , with keeping the Tablayout at the bottom and pointing to the current tab. Like this:
In the other words ,
Is it possible to group several pages(fragments) to a tab?
I think you should create custom FragmentPageAdapter for your ViewPager. That allows you replacing Tab1's base fragment (Current Page on your last picture) with another fragment (Another Page on your last picture).
You can do it e.g. after click on button on base fragment.
If you wont to go back to base fragment after click on Tab 1 you have implement OnTabSelectedListener having regard to setup with view pager.
I don't attach any code because I don't know how your code looks like.

How to make tabs/sub-fragments inside a tab/fragment in Android

I have implemented an ActionBar with 3 tabs in an android app. I also used ViewPager to switch between different tabs. Every tab is defined in a fragment.
The last tab is called "Setting". I have two different settings. One is "Simple" setting, and the other one is "Advanced" setting. How can I implement these two different settings in the "Setting" tab. Should I make kind of sub-fragments or two new tabs inside the main tab which is "Setting" tab? Can I also for example create two buttons at the top, and switch between them? Or any better idea? Which solution is easier and more efficient. I'm a newbie in Android.
I want to make something like this:
Hope this help
Take SettingFragment as Host fragment
Place both buttons on top and ViewPager below buttons
Take SimpleFragment and AdvanceFragment as items in ViewPager

ActionBar with tabs - weird issue when switching tabs

I have got a weird issue with the 3 tabs of my ActionBar :
When i go from my second tab to the third, onCreateView() is not called, i like it because values in my third tab are in the same state.
Now, i will switch to the first tab and go back to the third, and now onCreateView() is called, and i don't want that...
Someone knows how to avoid this ? I don't understand why there is a difference between my second and my first tab !
Thank you for reading
It's probably because of the offscreenlimit in viewpager (I suppose it's your case).
It's set by default to one which means that view pager holds one fragment at each side of your currently visible tab in memory. (And when it's in memory it means that onCreateView() gets not called)

Android-Implement swipe tabs in swipe tabs

I have three horizontal tabs A, B and C. They have been implemented using FragmentPagerAdapter. Is there a way I can again implement horizontal swipe tabs in each tab.
Tab A
-- Tab 1
-- Tab 2
-- Tab 3
Tab B
-- Tab 1
-- Tab 1
-- Tab 1
and so on.
Do you mean you want nested tabs? If so, I would suggest looking into the documentation for FragmentStatePagerAdapter
Assuming you have fragments set up for each tab, embed a FragmentStatePagerAdapter within the existing FragmentPagerAdapter.
Copy and convert your activity to a Fragment and embed it in the existing activity.
WARNING!
This design is HIGHLY warned against by Google! I would not suggest using it.
Anyway, hope it helps.

Add/Remove Tab and its content from tabhost

I have nine tabs(say 0 to 8), displaying only five tabs on screen.
The five tabs will be 0 to 3 of those nine tabs and fifth tab will be MORE Tab.
MORE tab will show Activity with GridView showing Image+Title of remaining nine tabs(say 4 to 8).
Now on click of any item(Image+Title) in GridView will replace the MORE Tab Image+Title and its content/activity with its respective activity.
I am able to replace the tab indicators(Image+Title) but struggling on replace its respective content/activity.
As on other similar thread they had suggested to use clearAllTabs and add/recreate require tabs again. But i feel clearing all tabs just to replace one tab is heavy.
I am using the TabActivity with Intents. As i know TabActivity is deprecated by its old app initially it had only 5 tabs but now requirement is to add few more tabs.
Need your help to implement this. If it not possible with TabActivity, then switching to fragment tabs does it help me?
I trying to implemtent this Image
I would recommend fragments for sure. I've used TabHost in the past and it was very problematic.
You can simply have Button at the top that control the visibility of the fragment below. With this way, you'll even be able to add transitions.
This link give a little more information on that topic. Separate Back Stack for each tab in Android using Fragments

Categories

Resources