Android的:如何动态地更改打开的选项卡选项卡、动态、Android

由网友(赐我万劫不复死而无墓)分享简介:我有一个Android应用程序,它有四个选项卡(我用用TabHost和TabSpecs主TabActivity)。在我的子活动。(在一个标签活动开了),我需要通过单击选项卡标题打开一个标签不,我不知道如何做到这一点。例如,我有一个按钮,在我的活动,当我点击它,它会打开一个不同的标签。就目前而言,这是我做的:意向意...

我有一个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.

阅读全文

相关推荐

最新文章