如何将附加内容传递给TabActivity中的intent?

时间:2010-11-19 22:31:00

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

我有一个TabActivity,可以托管很多标签。每个选项卡引用相同的活动,但是在活动内部执行逻辑以确定要加载的内容。我希望通过将布尔值传递给相应的选项卡来完成此操作。我怎么能这样做?

package com.stocktwits.activity;

import android.app.TabActivity;
import android.content.Intent;
import android.content.res.Resources;
import android.os.Bundle;
import android.widget.TabHost;

public class StockTwitsTabActivity extends TabActivity{
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.stocktwits_tab_activity);

        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, StreamActivity.class);

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

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

        intent = new Intent().setClass(this, StreamActivity.class);
        spec = tabHost.newTabSpec("mentions").setIndicator("Mentions",res.getDrawable(R.drawable.icon)).setContent(intent);
        tabHost.addTab(spec);

        intent = new Intent().setClass(this, StreamActivity.class);
        spec = tabHost.newTabSpec("directs").setIndicator("Directs",res.getDrawable(R.drawable.icon)).setContent(intent);
        tabHost.addTab(spec);

        intent = new Intent().setClass(this, StreamActivity.class);
        spec = tabHost.newTabSpec("more").setIndicator("More",res.getDrawable(R.drawable.icon)).setContent(intent);
        tabHost.addTab(spec);

        tabHost.setCurrentTab(0);
    }
}

2 个答案:

答案 0 :(得分:0)

听起来你做错了。为什么要将相同的活动传递给所有选项卡?使用不同的活动或不同的视图。不一样的活动。

答案 1 :(得分:0)

查看here

如果这是一个有效的解决方案,请告诉我