【问题标题】:Launch an other tab's using a button使用按钮启动其他选项卡
【发布时间】:2011-06-21 09:29:23
【问题描述】:

我创建了一个带有 tabhost 等的 android 项目。 我可以切换到我想要的视图,一切都很好。

现在,我想使用一个按钮来启动另一个选项卡...

这是我的 main.class :

public class Main extends TabActivity{

@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    Log.v("", "Welcome in Main");
    setContentView(R.layout.tab);

    TabHost tabHost = (TabHost)findViewById(android.R.id.tabhost);  // Le TabHost a des Tabs

    TabSpec firstTabSpec = tabHost.newTabSpec("tid1");  // TabSpec: new tab - TabSpec : setContent to the tab
    firstTabSpec.setIndicator("Informations", getResources().getDrawable(R.drawable.database)).setContent(new Intent(this,FirstTab.class));
    tabHost.addTab(firstTabSpec);

    TabSpec secondTabSpec = tabHost.newTabSpec("tid1");
    secondTabSpec.setIndicator("Graphiques", getResources().getDrawable(R.drawable.chart)).setContent(new Intent(this,SecondTab.class));
    tabHost.addTab(secondTabSpec);

    TabSpec thirdTabSpec = tabHost.newTabSpec("tid1");  // tid1 is firstTabSpec Id (used to access outside)
    thirdTabSpec.setIndicator("Réglages", getResources().getDrawable(R.drawable.settings)).setContent(new Intent(this,ThirdTab.class));
    tabHost.addTab(thirdTabSpec);

我试过了:

    public void secondJour(View v) {
    Log.v("", "onCLick 001");
    new Intent(this,SecondTab.class);
}

但它似乎没有运行(没有错误,但屏幕上没有新内容..)

你有解决办法吗?

感谢阅读!!!

【问题讨论】:

  • 你可以为按钮编写整个onClick方法吗?谢谢...
  • @Jim:谢谢并完成 ;-) 但没什么特别的!如果你想看看我是如何制作主要方法(管理标签的),问我;-)

标签: android android-layout android-intent android-tabhost


【解决方案1】:

使用startActivity(new Intent(this.Second.class))

【讨论】:

  • 太好了,谢谢,我正在运行,但我没有看到我的标签(它会在没有标签的情况下启动 second.class)。我可以显示标签吗? ^^
【解决方案2】:

使用startActivity(new Intent(this, SecondTab.class))

【讨论】:

  • 你在你的列表中写道“我已经创建了一个带有 tabhost 等的 android 项目。我可以切换到我想要的视图,一切都很好。”为什么你不能这样做二等舱?如果您不知道如何创建标签活动,我建议您阅读此developer.android.com/resources/tutorials/views/…
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2021-04-21
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2017-03-08
  • 1970-01-01
相关资源
最近更新 更多