0

如何使用标签栏传递参数?这是我下面的代码,当我单击任何选项卡栏时,我想在选项卡栏中启动活动时传递参数是传递参数,我该怎么做?

    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main2);
        setTabs() ;
    }
    private void setTabs()
    {
        addTab("payments", R.drawable.tab_home, myactivity1.class.class);
        addTab("My Account", R.drawable.tab_home, myactivity2.class);

        addTab("Spend Analyzer", R.drawable.tab_home, myactivity3.classs);
        addTab("Notification", R.drawable.tab_home, myactivity4.class);
        addTab("Help", R.drawable.tab_home, myactivity5.class);
    }

    private void addTab(String labelId, int drawableId, Class<?> c)
    {
        TabHost tabHost = getTabHost();

        Intent intent = new Intent(this, c);
        TabHost.TabSpec spec = tabHost.newTabSpec("tab" + labelId); 


        View tabIndicator = LayoutInflater.from(this).inflate(R.layout.tab_indicator, getTabWidget(), false);
        TextView title = (TextView) tabIndicator.findViewById(R.id.title);
        title.setText(labelId);
        ImageView icon = (ImageView) tabIndicator.findViewById(R.id.icon);
        icon.setImageResource(drawableId);

        spec.setIndicator(tabIndicator);
        spec.setContent(intent);
        tabHost.addTab(spec);

    }
}
4

1 回答 1

0

根据我的想法,您需要这样做

TabHost tabHost = getTabHost();

    TabSpec tabSpec1 = tabHost.newTabSpec("TEMP");
    tabSpec1.setIndicator("TEMP", getResources().getDrawable(R.drawable.temperatureicon));
    Intent itab1  = new Intent(this , Temp.class);
    itab1.putExtra("name", value);
    tabSpec1.setContent(itab1);


tabHost.addTab(tabSpec1);
于 2013-01-23T14:00:13.520 回答