开发者

Why are the last two tabs in an android app doing the same thing?

I'm working on adding a tab to an application, but the last two tabs (regardless of order) are launching the same activity. If I go down to two tabs they both work correctly, but when I add the third the last two result in the same activity launching. Any suggestions?

public void uiConnected() {
    Log.d(TAG, "UI Connected");

    tabHost.clearAllTabs();

    intent.setClass(this, NowPlayingActivity.class);
    spec = tabHost.newTabSpec("nowplaying").setIndicator("Now Playing").setContent(intent);
    tabHost.addTab(spec);

    intent.setClass(this, PlaylistActivity.class);
    spec = tabHost.newTabSpec("playlist").setIndicator("Playlist").setContent(intent);
    tabHost.addTab(spec);

    intent.setClass(this, LibraryActivity.class);
    spec = tabHost.newTabSpec("library").setIndicator("Library").setContent(intent);
    tabHost.addTab(spec);

    if (MPDApplication.DEBUG) {
        tabHost.setCurrentTabByTag(app.sp.getString(AppPreferenceActivity.KEY_APP_LASTTAB, "playlist"));
    } else {
        tabHost.setCurrentTabByTag(app开发者_如何学Python.sp.getString(AppPreferenceActivity.KEY_APP_LASTTAB, "nowplaying"));
    }
}


Create new Intents for each tab. Right now, you are setting all three tabs to a single Intent object.

Or, don't use Intents for tabs, but use Views instead.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜