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.
Related
I want to create a tab menu similar to TabHost but I would like to use some other elements, not only buttons in that menu, and also be able to bind some other actions than start new activity to buttons.
Basically I need an activity with a layout that I will be able to show in part of every other activity just like TabHost with ActivityGroup. Is it possible at all? Ask me if you didn't understand my idea.
how about using a horizontal scrollview that has a linear layout (with horizontal orientation) , which has all the views that you've mentioned?
beneath it , put a fragment container which can change its content.
if you are unfamiliar with fragments , check the api-demos , or , for "old" versions of android (gingerbread and below) , check the support library demos (v4) .
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
i have develop one application in which tab layout in main file now i would like to set tablayout inside 2nd number tab,so what thing can i do? help me.
its "tab inside tab"
I think you want to give sub-options while clicking on 2nd tab button. For that, why dont you create layout with 2-3 options as you wants. And make it visible/invisible based on the 2nd button's click.
You can make visible/invisible any view by using setVisibility(View.VISIBLE) and setVisibility(View.GONE) method.
I suppose you can't embed a TabHost inside another TabHost. You can do what #Paresh said. Implement your own view switching. If you want an entire Activity embedded - take a look at ActivityGroup or the Fragments framework which you can use through the Compatibility Framework. Good luck.
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
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.