How to make tabs/sub-fragments inside a tab/fragment in Android - 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

Related

ActionBarSherlock TabNavigation

I have gotten my tabs up and running with Sherlock Fragments. So i have two tabs and two fragments. Now what i want is that when i click on a button in one of the fragments, I want another fragment to open up, but it should be inside the tab that contained the original fragment. Can anyone show me how this can be done ?
Actually Nested Fragments are not possible directly. I had a similar issue and but the Fragment to be shown was small and simple. So I just played with setVisibility() as LinearLayout.GONE and LinearLayout.VISIBLE
On the Fragment initialization, I hid the second layout and when I need to show the other fragment, I hid the first layout and showed the second layout. It worked great for me!

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

Right way to switch between tabs and change layout of the application?

I'm currently developing an application that has a tab bar, and 3
different views: the first is a master-detail, the second one a
gallery, the third is a simple webview.
I was using the TabActivity, but since Android 3.0, this class is
deprecated and Android reference
suggests to use Fragments.
I switched then to an ActionBar, with Tabs and Action
Items. Inseide the first tab item I have a layout with 2 fragments (my
master-detail view). When I switch through tabs I want that my layout
change as I described above, so I thought to hide the left fragment
(the master listview) and work only in the detail fragment.. but with
this solution I have only one main activity with a lot of fragments
attached to it, and for each fragment displayed I need to modify the
Action Item shown and handle different actions in
OnOptionItemSelected.
Is this a good way to implement this kind of
application or should I consider different solutions?
You should have a single fragment container where the fragments are replaced depending on the tab selected.
One activity and multiple fragments is the right approach.

Android - Change content view of TabHost

I try to create a android application with tabHost and I would like to avoid to set intent(activity) for the content of these tabs.
I succeed to create my tabMenu but I would like to change the view of one tab.
How I can do that ?
For example I have one view for Tab1 and two views for Tab2 (when the user click on the button of Tab2_view1 then the content change to Tab2_view2 and the indicator doesn't change (stay on "tab2")).
I hope it is possible but I don't find the way to do that without using different activities for each tabs.
Maybe my conception is bad (I am novice in Android dev.)...
Thank you very much for your help,
Fred
Android has ActivityGroup for the same purpose that you are looking for. By using ActivityGroup you can show multiple views in a single Tab by maintaining the stack of the Views.
ActivityGroup Example 1
ActivityGroup Example 2
Fragment - Answer to me by hackbod

TabWidget problem with new activities

I use Tab Widget like in documentation example TabWidget
I have two tabs, and in every tab when I press some button I need to load another different activity. My question is how to achive that I have that two tab on another activities like headers ?
I could create that tabs in new activities but it wouldn't remember choosen activity for another tab. How to solve this ?
This is not possible out of the box. The normal TabHost doesn't provide any facility to change the content of a tab after it is created. If you can use views as your tab content, you can, however, flip between the views within a tab so that to get the effect you are after.
If you absolutely must use a new Activity, then you will have to implement your own TabHost which allows swapping tab content after it is created.

Categories

Resources