0

2つのタブを持つTabHostがあります。ユーザーがどちらかのタブをクリックしたときを知りたい。どうすればこれを達成できますか?

Resources res = getResources(); // Resource object to get Drawables
        TabHost tabHost = getTabHost();  // The activity 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, Main.class);

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

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

        tabHost.setCurrentTab(0);
4

1 に答える 1

1

onTabChangeListener(http://developer.android.com/reference/android/widget/TabHost.OnTabChangeListener.html)を使用して、それをTabHostに渡したいと思います。http://developer.android.com/reference/android/widget/TabHost.html#setOnTabChangedListener%28android.widget.TabHost.OnTabChangeListener%29を参照してください

誰かがタブを切り替えるたびに効果的に通知を受け取ることができます。

于 2011-05-03T21:33:32.650 に答える