我称之为Tabactivity。
在标签活动中,从第一个标签切换到另一个名为Float的活动,该活动与TabActivity无关。当条件变为True时,从此活动我想在TabBar中显示第三个选项卡。如何从标签活动中打开第三个标签。
以下是我的Tabactivity类的代码
public class MainTabBar extends TabActivity
{
TabHost tabHost;
Intent intent;
@Override
public void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
setContentView(R.layout.maintab);
addTab1(Display.class);
addTab2(History.class);
addTab3(Capture .class);
addTab4(AboutUs.class);
}
private void addTab1( Class<?> c)
{
TabHost tabHost = getTabHost();
Intent intent = new Intent(this, c);
TabHost.TabSpec spec = tabHost.newTabSpec("Tab1");
View tabIndicator = LayoutInflater.from(this).inflate(R.layout.hometab, getTabWidget(), false);
spec.setIndicator(tabIndicator);
spec.setContent(intent);
tabHost.addTab(spec);
}
private void addTab2( Class<?> c)
{
TabHost tabHost = getTabHost();
Intent intent = new Intent(this, c);
TabHost.TabSpec spec = tabHost.newTabSpec("Tab2");
View tabIndicator = LayoutInflater.from(this).inflate(R.layout.macstab, getTabWidget(), false);
spec.setIndicator(tabIndicator);
spec.setContent(intent);
tabHost.addTab(spec);
}
private void addTab3( Class<?> c)
{
TabHost tabHost = getTabHost();
Intent intent = new Intent(this, c);
TabHost.TabSpec spec = tabHost.newTabSpec("Tab3");
View tabIndicator = LayoutInflater.from(this).inflate(R.layout.abouttab, getTabWidget(), false);
spec.setIndicator(tabIndicator);
spec.setContent(intent);
tabHost.addTab(spec);
}
private void addTab4( Class<?> c)
{
TabHost tabHost = getTabHost();
Intent intent = new Intent(this, c);
TabHost.TabSpec spec = tabHost.newTabSpec("Tab4");
View tabIndicator = LayoutInflater.from(this).inflate(R.layout.contacttab, getTabWidget(), false);
spec.setIndicator(tabIndicator);
spec.setContent(intent);
tabHost.addTab(spec);
}
}
使用旗帜或任何其他简单的方式是上面的东西,请建议我的朋友,我是新的android
答案 0 :(得分:1)
您可以使用标签索引显示第三个标签
tabHost.setCurrentTab(2);