TabWidget problem with new activities - android

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.

Related

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

Android how to change views?

Basically I need some suggestions which is the best way to switch views in my situation. My Application has 5 different tabs. In every single tab I'm using activity manager to start as many activities that I need inside this tab. Now I have a little problem. In one of the tabs I need to create something like three different tabs. In second tabs I used 3 buttons, which switch the views via viewflipper. But now I have like 2 or 3 views inside every new tab (or button) which I need to switch. I did it with viewflipper but it's actually not what I want, because I want to use back button to switch between views.
Example:
MAIN TAB BAR : ONE TWO THREE FOUR FIVE
SECOND TAB BAR INSIDE TAB THREE / OR JUST THREE BUTTONS : TAB-A TAB-B TAB-C
IN TAB-A I have only one view.
IN TAB-B I have 2 views. View 1 is a listView and onItemClick switch view 2.
IN TAB-C I have same scenario like in TAB-B.
P.S. View 1 and View 2 directly can change to TAB-C.And I need to be able to send data between the views/activities.
Any suggestions how to do that? ViewFlipper or something else.
Better use activities inside the tab THREE and create three buttons which starts new activity.And you can use ViewFlipper inside these activities to change the views,or viewswticher.It depends on your needs.
You can override the onBackPressed in your activity to change the default behaviour of the back button
http://developer.android.com/reference/android/app/Activity.html#onBackPressed()

Is there a way to display fragments in TabHost?

I'd like to show a different fragment in a TabHost, for every tab. But
it seems that there's no easy way to do this. TabHost can only accept
A. Views or B. Intents that launch Activities when the user selects a
tab.
Going with A means that I have to initialize every fragment and load
them into container Views that are given to the TabHost. But I want
these fragments to load only when needed - when the user selects their
tab that is.
Going with B means that I load the fragments into separate Activities
for each tab. But I'd like the fragment to be able to reach the
"original" parent Activity, not just some shell Activity that hosts
them in a tab content.
Am I missing something? Is there a way to manage fragments with
TabHost properly?
Some hits here:
fragment Support with Tabhost
Android 1.6 & Fragment & Tabhost
For what I understood, "link" a fragment inside a TabHost isn't allowed, you need to create activities that include your fragments and then call these activities from TabHost.
EDIT
the "official solution" from Google, and with nice animations.

add dynamic view to android tabhost

How can I add a dynamic view in a TabHost.
I have two tabs i.e. TabA and TabB. In TabA, I have 2 buttons and I want to set the layout (I have 2 different XML layout's) of TabB, depending upon the button pressed in TabA.
Can anyone help me.
Thank you!
That depends on the implementation of your TabHost. Have you used Activities or Views as Tabs?
Generally in your TabActivity you could use getTabHost().getTabWidget().getChildAt(index) or another method to get the view of a Tab.
If you use Activities as the children, you could also start a new Intent with your ActivityGroup and set a new view within the onCreate() method.
If you have problems finding examples for ActivityGroups with TabHosts, I can provide you a code sample showing you how to do it and also how to change the view within another tab by clicking a button.

TabHost View Problem

I have a problem in layout.
I am using TabHost in my application. In that there are 4 Tabs.
In one of the Tab i have used 3 Buttons.
What I wanted to do is :
When i click on one of the Button, the TabHost and the Button should remain as it is and it should display me the contents (Set according to onClickListener) in that activity itself.
Take a look at the answer of this question: Changing the view within the Android Tab Widget
Ok, but the thing i don't understand: where should it show you the buttonClick result? If you want to set the activity in tab not to reload each time, you should use .addFlags(Intent.FLAG_ACTIVITY_SINGLE_TOP) in the corresponding tabspec declaration

Categories

Resources