从活动设置制表 [英] Set a Tab from an activity
问题描述
我有一个TabActivity和内5片5活动各一个。我想设置我的标签之一,但不是从TabActivity(点击顶部的选项卡上),但任何标签的活动,例如点击活动3(这是asociated与第三个标签)的按钮。
在我的TabActivity有一个变量 mTabhost
,我可以用它来设定
I have a TabActivity and inside 5 tabs with 5 activities each one. I want to set one of my tabs but not from the TabActivity(clicking on the tab on the top) but from an activity of any tab, for example clicking on a button of activity 3(which is asociated with the 3rd tab).
In my TabActivity there is a variable mTabhost
, which I can use to set the selected tab with
mTabHost.setCurrentTab(0);//home
我想我需要访问来自Activity1-2-3-4的变量,这样做静态变量行不通的。
I guess I need access to that variable from Activity1-2-3-4, and doing that variable static doesnt work.
推荐答案
假设你有一个 MyTabActivity
为 TabActivity
,它承载5 活动
(IES)。
如果你想改变里面的 SecondActivity
的标签,你会写code这样的事情。
Say you have a MyTabActivity
as TabActivity
, which hosts 5 Activity
(ies).
If you want to change the Tabs inside SecondActivity
, you would write the code something like this.
MyTabActivity myTabs = (MyTabActivity) this.getParent();
在这里,你有你的MyTabActvity
您可以更改标签,如:
Here you have your MyTabActvity you can change the tabs like:
myTabs.getTabHost().setCurrentTab(index);
这篇关于从活动设置制表的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!