如何启动与特定标签的活动? [英] How to launch an activity with a specific tab?

查看:186
本文介绍了如何启动与特定标签的活动?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经经历了很多例子,问题和教程走了,但我从来没有见过一个活动启动(推出一个新的intent)与特定的标签。我知道,你可以使用 .setCurrentTab 切换到一个标签,但是这只能从父活动选项卡中完成。如何启动从不同的活性在一个活动包含一个特定标签?可能吗?如果是这样,那么如何?

在我的code,在标准推出的活动用户显示的第一个选项卡,但我想他去第四个选项卡的情况下,他正在从另一项活动重定向。 我TabHost code(MyTabActivity):

  INT的tabIndex = 0;

          mTabHost.addTab(mTabHost.newTabSpec(TOP10)setIndicator(十佳)setContent(R.id.Top_10)。);
          mTabHost.addTab(mTabHost.newTabSpec(计费)setIndicator(计费)setContent(R.id.Billable));
          mTabHost.addTab(mTabHost.newTabSpec(产品)setIndicator(产品)setContent(R.id.Product)。);
          mTabHost.addTab(mTabHost.newTabSpec(常规)setIndicator(常规)setContent(R.id.General)。);


          mTabHost.setCurrentTab(的tabIndex);
 

现在在另一个活动:

 公共无效gotoTab(){
//这将带我去的第一个选项卡
意图I =新的意图(这一点,MyTabActivity.class);
startActivity(ⅰ);
完();
//如何我让它带我去的第四个选项卡?
}
 

解决方案

您需要将自己与 setCurrentTab 处理它的新的活动的构造。

在呼吁,应该把更多的价值在意向 -

 意向书我=新的意图(这一点,MyTabActivity.class);
i.putExtra(FirstTab,4);
 

而在MyTabActivity的构造 -

 意图I = getIntent();
INT tabToOpen = i.getIntExtra(FirstTab,-1);
如果(tabToOpen!=  -  1){
    //打开正确的选项卡
}
 

I've gone through many examples, questions and tutorials but I've never seen an activity launch (launch a new intent) with a specific tab. I know that one can use .setCurrentTab to switch to a tab, but this can be done only from inside the parent activity tab. How about launching a specific tab contained in one activity from a different activity? Is it possible? If so, then how?

In my code, on a standard activity launch user is shown the first tab, but I want him to go to the fourth tab in case he is being redirected from another activity. My TabHost code (MyTabActivity):

int tabIndex = 0;

          mTabHost.addTab(mTabHost.newTabSpec("top10").setIndicator("Top 10").setContent(R.id.Top_10));
          mTabHost.addTab(mTabHost.newTabSpec("billable").setIndicator("Billable").setContent(R.id.Billable));
          mTabHost.addTab(mTabHost.newTabSpec("product").setIndicator("Product").setContent(R.id.Product));
          mTabHost.addTab(mTabHost.newTabSpec("regular").setIndicator("Regular").setContent(R.id.General));


          mTabHost.setCurrentTab(tabIndex);

Now in another activity:

public void gotoTab() {
//This will take me to the first tab
Intent i = new Intent(this, MyTabActivity.class);
startActivity(i);
finish();
//How to I make it take me to the fourth tab?
}

解决方案

You will need to handle it yourself with setCurrentTab in the new activity's constructor.

While calling, you should put additional values in the intent -

Intent i = new Intent(this, MyTabActivity.class);
i.putExtra("FirstTab", 4);

And in constructor of MyTabActivity -

Intent i = getIntent();
int tabToOpen = i.getIntExtra("FirstTab", -1);
if (tabToOpen!=-1) {
    // Open the right tab
}

这篇关于如何启动与特定标签的活动?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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