在选项卡上使用Intent时关闭

时间:2012-04-21 11:01:10

标签: android android-intent tabs android-tabhost shutdown

我创建了一个包含3个活动的tabHost,所以当我点击标签时,我会更改活动。

这是第一项活动的代码:

public class estadisticas extends Activity {

@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.estadisticas);
    // TABS

    Intent intent1 = new Intent(estadisticas.this, clasificacion.class);
    Intent intent2 = new Intent(estadisticas.this, novedades.class);
    Resources res = getResources();
    TabHost tabHost = (TabHost) findViewById(R.id.mytabhost);
    tabHost.setup();

    //tab 1
    TabSpec tab1 = tabHost.newTabSpec("estadisticas");
    tab1.setIndicator(getString(R.string.statistics),res.getDrawable(R.drawable.estadisticastabs));
    tab1.setContent(R.id.tab1);
    tabHost.addTab(tab1);

    //tab 2 
    TabSpec tab2 = tabHost.newTabSpec("clasificacion");
    tab2.setIndicator(getString(R.string.scores),res.getDrawable(R.drawable.estadisticastabs));
    tab2.setContent(intent1);
    tabHost.addTab(tab2);

    //tab 3
    TabSpec tab3 = tabHost.newTabSpec("novedades");
    tab3.setIndicator(getString(R.string.whatsnew),res.getDrawable(R.drawable.estadisticastabs));
    tab3.setContent(intent2);
    tabHost.addTab(tab3);

    // END TABS

当我点击两者(或tab2或tab3)时,我会关机。

我哪里错了? 感谢。

1 个答案:

答案 0 :(得分:0)

你错过了这2行

TabHost tabHost = getTabHost();
        TabHost.TabSpec spec;   

试试这段代码:

 @Override
        public void onCreate(Bundle savedInstanceState) {
            super.onCreate(savedInstanceState);
            setContentView(R.layout.tab);
           // LocationManager locManager = (LocationManager) getSystemService(LOCATION_SERVICE);

    //if (!locManager.isProviderEnabled(LocationManager.GPS_PROVIDER)){


           //     }

           // SetupTabs();
            Resources res = getResources(); 
            TabHost tabHost = getTabHost();
            TabHost.TabSpec spec;  
            Intent intent;

            intent = new Intent().setClass(this, Addplace.class);
            spec = tabHost.newTabSpec("BYM").setIndicator("By Manually",res.getDrawable(R.drawable.marker_unselected)).setContent(intent);
            tabHost.addTab(spec);

           // createGpsDisabledAlert();
            intent = new Intent().setClass(this, HelloAndroidGpsActivity.class);
            spec = tabHost.newTabSpec("BGPS").setIndicator("By GPS",res.getDrawable(R.drawable.marker_unselected)).setContent(intent);
            tabHost.addTab(spec);
          //  }


            intent = new Intent().setClass(this, mapclass.class);
            spec = tabHost.newTabSpec("BYM").setIndicator("By Map", res.getDrawable(R.drawable.marker_unselected)).setContent(intent);
            tabHost.addTab(spec);

          //  tabHost.setCurrentTab(1);

        }