如何以编程的机器人从片段切换标签? [英] How to switch tabs programatically in android from fragment?
问题描述
我实现了一个 TabActivity
延伸 FragmentActivity
。它有5个选项卡每个标签是一个片段
。我所寻找的是对标签编程之间切换。
有关,例如::如果我在TAB4。在按钮单击我想从 TAB4移动到TAB1
。尝试了很多,但无法找到这种情况的解决方案。
试着用以下,但ID不会帮助
从SecondTab
公共无效switchTabInActivity(字符串值){
FirstTab父母;
父=(FirstTab)getActivity()的getParent()。
parent.switchTab(值);
}
TabActivity
/ **更改选项卡* /
公共无效switchTab(字符串tabno){
this.onTabChanged(tabno);
}
最后,我可以在标签之间编程的片段用code以下行开关
TabHost主机=(TabHost)getActivity()findViewById(android.R.id.tabhost)。
host.setCurrentTab(2);
希望这将有助于部分之一。
I have implemented a TabActivity
which extends FragmentActivity
. It has 5 tabs each tab is a Fragment
. What i am looking for is to switch between the tabs programatically.
For eg: if i am in tab4. On button click i want to move from tab4 to tab1
. Tried a lot but couldn't find the solution for this.
Tried with the following but id doesn't helps
From SecondTab
public void switchTabInActivity(String value){
FirstTab parent;
parent = (FirstTab) getActivity().getParent();
parent.switchTab(value);
}
TabActivity
/** To Change Tab*/
public void switchTab(String tabno){
this.onTabChanged(tabno);
}
Finally i can switch between the tabs programatically from Fragments using the following line of code
TabHost host = (TabHost) getActivity().findViewById(android.R.id.tabhost);
host.setCurrentTab(2);
Hope it will help some one.
这篇关于如何以编程的机器人从片段切换标签?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!