Android的:如何动态地更改打开的选项卡 [英] Android:How to change opened tab dynamically

查看:107
本文介绍了Android的:如何动态地更改打开的选项卡的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个Android应用程序,它有四个选项卡(我用用TabHost和TabSpecs主TabActivity)。 在我的子活动。(在一个标签活动开了),我需要通过单击选项卡标题打开一个标签不,我不知道如何做到这一点。 例如,我有一个按钮,在我的活动,当我点击它,它会打开一个不同的标签。 就目前而言,这是我做的:

意向意图=新的意图(myActivity.this,myTabActivity.class);
intent.putExtra(ComeFrom,真正的);
intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
startActivity(意向);

然后在TabActivity,如果我得到真正的阅读ComeFrom多余的我打开了希望选项卡,但问题是,它杀死所有其他activies。所以,如果有人知道一个更好的(清洁剂)的方式来做到这一点伎俩,请告诉我...

I have an Android application which has four tabs (I use a main TabActivity with TabHost and TabSpecs). In one of my sub activity (activity opened in a tab), i need to open a tab not by clicking on the tab title and i don't know how to do this. For example, i have a button in my activity and when i click on it, it opens a different tab. For the moment, it is what i do:

Intent intent = new Intent(myActivity.this, myTabActivity.class);
intent.putExtra("ComeFrom", true);
intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
startActivity(intent);

Then in the TabActivity, if i get true reading the "ComeFrom" extra i open the wished tab but the problem is that it kills all the other activies. So, if someone knows a better (cleaner) way to do that trick, please tell me...

推荐答案

您必须使用TabHost的setCurrentTab(...)了点。在我的项目之一,我创造了主要活动的静态方法(一个与TabHost),命名为swtichToTab(INT标签)。在我subactivites(这些标签中)可能就可以致电MainActivity.switchToTab()来触发切换。

You have to use TabHost's "setCurrentTab(...)" for that. In one of my projects, I created a static method in the main Activity (the one with the TabHost), named "swtichToTab(int tab)". In my subactivites (those inside the tabs) could then just call "MainActivity.switchToTab()" to trigger switching.

这可能不是最干净的方法,我相信你能做到这一点使用广播的意图了。

It may not be the cleanest method, I'm sure you can achieve this using broadcast intents too.

这篇关于Android的:如何动态地更改打开的选项卡的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆