Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Update tabs from a tab's activity in a Android TabHost

I have a TabActivity and am going to have 3 or 4 tabs.

In TabA, I would like to have an ExpandableListView, which will list products. I would like TabC to act as a sort of "shopping cart", probably with a ListView of itself.

Is there a way to interact with the TabHost from the Activity? I would like to be able to click a button inside of TabA and have it update and switch to TabC. Is this possible? Can I get the Tab's activities call its parents methods?

like image 470
Josh Lillie Avatar asked May 31 '10 18:05

Josh Lillie


People also ask

How do I use tabhost for Android?

How do I use tabHost for Android? Before getting into example we should know what is tab host in android. Tab host holds set of tabs. Each tab contains either fragment or activity as per project specification. The user can scroll tabs from left to right or right to left.

What is Tabtab layout in Android?

Tab layout is gives us the ability to insert multiple android activities including layout files on a single activity to share your app content online. Tabhost hold all the created activities into a single frame layout and developer can add multiple tab menu on application and each tab holds an activity screen to show their own content.

How do I launch an activity as the tab content?

3. setContent (Intent intent): This method is used to specify an intent to use to launch an activity as the tab content. Whenever a user click on this tab an activity is open and display the content. Below we set an intent that is used to launch an activity as the tab content.

How to use tabs in interface form in Android?

A simple and effective method is to use tabs in your interface form which is done using TabHost in Android. Important Note: A Tabhost holds two children’s from which one is use to set the labels that the users clicks to select tab other is a FrameLayout that is used to display the content of that page.


1 Answers

If you implement your tabs as views, rather than individual activities, this would be far simpler, run faster, take up less memory, and be a better solution IMHO.

That being said, in the Tab A Activity, call getParent() to get at the TabActivity. Then, you can use the methods pointed out by disretrospect.

like image 101
CommonsWare Avatar answered Nov 10 '22 16:11

CommonsWare