【问题标题】:How can I determine the current selected tab?如何确定当前选择的选项卡?
【发布时间】:2011-05-06 17:49:47
【问题描述】:

我有一个有两个选项卡的 TabHost。每个标签都有自己的意图:

TabHost.TabSpec spec;  // Resusable TabSpec for each tab
        Intent intent;  // Reusable Intent for each tab

        // Create an Intent to launch an Activity for the tab (to be reused)
        intent = new Intent().setClass(this, ARActivity.class);

        // Initialize a TabSpec for each tab and add it to the TabHost
        spec = tabHost.newTabSpec("trending").setIndicator("Trending",res.getDrawable(R.drawable.icon)).setContent(intent);
        tabHost.addTab(spec);

        // Do the same for the other tabs
        intent = new Intent().setClass(this, WatchlistActivity.class);
        spec = tabHost.newTabSpec("watchlist").setIndicator("Watchlist",res.getDrawable(R.drawable.icon)).setContent(intent);
        tabHost.addTab(spec);

        tabHost.setCurrentTab(0);

当我在 ARActivity 或 WatchlistActivity 中时,如何确定选择了哪个选项卡?

【问题讨论】:

    标签: java android tabs android-intent android-tabhost


    【解决方案1】:

    您好,您可以使用两个活动的 tabHost.getCurrentTab() onResume() 来检测您选择了哪个选项卡。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2011-05-14
      • 2010-12-24
      • 1970-01-01
      • 2019-08-24
      • 2010-09-22
      相关资源
      最近更新 更多