Opening the activity in another Tab on Click

╄→гoц情女王★ 提交于 2019-12-13 06:57:17

问题


I am using TabHost in my application and I want to open a webPage when I click on the Item from the List of one Tab into the another Tab.

I mean the list is in one Tab and when I click on an item from the list, I want to open the WebPage in to another Tab.

Can I doe this? If yes than please tell me how?

Thanks, david


回答1:


In the assumption that you've got your tabs setup like this :

LocalActivityManager localActivityManager = new LocalActivityManager(this, false);
tabHost.setup(localActivityManager);

TabSpec spec = tabHost.newTabSpec("tab1").setIndicator("My List").setContent(R.id.layout_tab1);
tabHost.addTab(spec);

spec = tabHost.newTabSpec("tab2").setIndicator("My Browser").setContent(R.id.layout_tab2);
tabHost.addTab(spec);

In your action (a button click in the snippet below), just set the current tab on your tabhost.

btnSearch.setOnClickListener(new View.OnClickListener() {
    public void onClick(View v) {
        tabHost.setCurrentTab(1);
    }
});


来源:https://stackoverflow.com/questions/4582727/opening-the-activity-in-another-tab-on-click

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!