rogerstone
rogerstone

Reputation: 7671

How can i invoke a tab from another tab in android?

I am using the android tab layout. 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?

Upvotes: 1

Views: 161

Answers (2)

Robby Pond
Robby Pond

Reputation: 73484

Add a ListView.onItemClickListener

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

Upvotes: 0

Cristian
Cristian

Reputation: 200090

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");

Upvotes: 4

Related Questions