Android-Implement swipe tabs in swipe tabs - android

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.

Related

fragment automatically refreshed in viewpager

I have viewpager with 4 tabs, and using fragments in each tabs. And i have webview in each fragment. when I was in the first tab there are no mistakes, until the third tab. When i back to first tab, fragment refresh automatic. It make webview loadUrl() again. I don't want it. How to stop that refresh ?
Another explain:
I have 4 tabs. I call it, Tab AA, BB, CC, and DD with adjacent. When I in Tab AA and go to Tab BB, there are no mistakes. But when I in Tab AA go to CC and go back to tab AA, the fragment in tab AA refresh again. And i want to know explanation about lifecycle in viewpager ? Thanks..
According to http://developer.android.com/reference/android/support/v4/view/ViewPager.html
you can use setOffscreenPageLimit to set the number of pages that should be retained to either side of the current page in the view hierarchy in an idle state. Pages beyond this limit will be recreated from the adapter when needed.
Please take a look at the ViewPager Documentation. The default behaviour is to retain 1 page either side of what's currently displayed. You can change it using setOffscreenPageLimit (int limit)
just use
viewPager.setOffscreenPageLimit(4);

Second set of tabs in an Android fragment

I want to add a second row of tabs to my Android application on the second fragment accessed from the ActionBar tabs.
Tab 1 shows fragment 1.
Tab 2 shows fragment 2 but I would like fragment 2 to have a second row of tabs so it will show fragment a or b.
But it seems like fragments within fragments cannot be done and an ActionBar submenu can't be switched on or off. I have also tried with a FragmentStatePagerAdapter with a TabHost and a ViewPager which displays the tabs fine but does not display the fragments. Is there any other way to do this?
If you know the new Design Support Library ....
In your second fragment you can use TabLayout introduced in design support library 22 . Which is same as Actionbar tabs.
So just add the TabLayout in your second fragment XML.
And TabLayout has a method setUpWithViewPager(). So you can easily setup your tabs.
I hope it helps you.
here is the reference http://android-developers.blogspot.in/2015/05/android-design-support-library.html

Material design sliding tabs not accessing more than two fragments

I have designed material design sliding tabs in android. I have added 3 tabs and want to change the UI at runtime from main activity but only 2 fragments has been instantiated and accessed except the 3rd. how to get the 3rd fragment to be instantiated and accessed?
By default the offscreenPageLimit for the ViewPager is 1. so, the ViewPager loads and extra one page from left and one page from right (total 3 pages).
You can change that by calling ViewPager.setOffscreenPageLimit(2);
this will load a 2 pages from each side (total 5 pages).
Refer this
Implement Sliding Tab Layout

Control two fragments within a tab

I was hoping someone could point me in the right direction when using fragments within a tab. I have a mutiple tab application. On one of the tab pages I have broken down the content into two separate fragments.
The issue is I do not want the fragment activity I using to control the tab to control also control the two fragments being displayed. I want an something between the two elements such as another fragmentactivity to control the fragments used as content.
Is this possible and if so how?
Tab Fragment
tab 1 tab2 tab 3
tab2 : display is two fragments
tab2 -> anther fragmentActivity -> two displayFragments
Transition to FragmentActivity
I believe I've found my answer. This can't be done. My fragments need to response to a fragmentActivity and the fragmentTransaction only transitions between fragments not activities. So they will have to respond to my activity controlling the tabs.

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