简体   繁体   English

从选项卡更改为另一个

[英]change from a tab to another

i want to make an intent from a tab to another.. how can i do that? 我想从一个标签到另一个标签..我该怎么做? i only now how to make between activity's. 我现在只在活动之间做些什么。 and i need to go from a tab to another.. 我需要从一个选项卡转到另一个。

i have this code for the tabs 我有这些标签的代码

public class Main extends TabActivity

{ {

@Override
protected void onCreate(Bundle savedInstanceState)
{
    // TODO Auto-generated method stub
    super.onCreate(savedInstanceState);
    setContentView(R.layout.main);



     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, Contas.class);
        Intent a = new Intent(Main.this, Contas.class);
        Intent b = new Intent(Main.this, Registros.class);
        Intent c = new Intent(Main.this, Relatorios.class);
        // Initialize a TabSpec for each tab and add it to the TabHost
        spec = tabHost.newTabSpec("Contas").setIndicator("Contas",
                          res.getDrawable(R.drawable.ic_tab_accounts))
                      .setContent(a.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP));
        tabHost.addTab(spec);


        // Do the same for the other tabs
        //intent = new Intent().setClass(this, Registros.class);
        spec = tabHost.newTabSpec("Registros").setIndicator("Registros",
                          res.getDrawable(R.drawable.ic_tab_registry))
                      .setContent(b.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP));
        tabHost.addTab(spec);

        //intent = new Intent().setClass(this, Relatorios.class);
        spec = tabHost.newTabSpec("Relatorios").setIndicator("Relatorios",
                          res.getDrawable(R.drawable.ic_tab_reports))
                      .setContent(c.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP));
        tabHost.addTab(spec);

        tabHost.setCurrentTab(0);


}

} }

Rather then calling intent you can just set the desired tab selected. 只需调用所需的选项卡,然后再调用意图即可。 tabHost.setCurrentTab(index)

Rather then calling intent you can just set the desired tab selected. 只需调用所需的选项卡,然后再调用意图即可。 Use 采用

intent.putExtra("tabIndex", index);

and call the activity. 并致电活动。 Now in the calling Activity's onCreate() or onResume() use 现在在调用Activity的onCreate()onResume()使用

int index = getIntent().getExtraInt("tabIndex", -1);
if(index != -1)
    tabHost.setCurrentTab(index);

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM