简体   繁体   English

如何从android中的另一个选项卡调用一个选项卡?

[英]How can i invoke a tab from another tab in android?

I am using the android tab layout. 我正在使用android标签布局。 I have 4 tabs.My first tab "Home" is a list view.I want to invoke the fourth tab on the click of a list item in my "Home" tab.How can i achieive this? 我有4个标签。我的第一个标签“主页”是列表视图。我想在“主页”标签中单击列表项时调用第四个标签。如何实现此目的?

You can put this inside a child activity: 您可以将其放在子活动中:

((YourTabActivity)getParent()).getTabHost().setCurrentTab(1);

In the case above, the second tab will be selected. 在上述情况下,将选择第二个选项卡。 Or if you use tags to reference your tabs, which is recommended, you can use: 或者,如果建议使用标签来引用选项卡,则可以使用:

((YourTabActivity)getParent()).getTabHost().setCurrentTabByTag("MY_SECOND_TAB");

Add a ListView.onItemClickListener 添加一个ListView.onItemClickListener

listView.setOnItemClickListener(new OnItemClickListener() {
    public void onItemClick(AdapterView av, View v, int position, long id) {
        mTabHost.setCurrentTab(3);
    }
});

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM