TabHost、TabActivity,选项卡 |
问题:11-26 07:18:09.174: E/AndroidRuntime(2545): Caused by: java.lang.IllegalArgumentException: you must specify a way to create the tab indicator. |
问题代码: TabHost tabHost = this.getTabHost(); /*TabSpec tab1 = tabHost.newTabSpec("tab1");
TabSpec tab2 = tabHost.newTabSpec("tab2");
TabSpec tab3 = tabHost.newTabSpec("tab3");
//
View view1 = View.inflate(this, R.layout.tab1_layout, null);
tab1.setIndicator(view1);
View view2 = View.inflate(this, R.layout.tab2_layout, null);
tab1.setIndicator(view2);
View view3 = View.inflate(this, R.layout.tab3_layout, null);
tab1.setIndicator(view3);
//
Intent intent1 = new Intent(this, Test1Activity.class);
tab1.setContent(intent1);
Intent intent2 = new Intent(this, Test2Activity.class);
tab2.setContent(intent2);
Intent intent3 = new Intent(this, Test3Activity.class);
tab3.setContent(intent3);
//
tabHost.addTab(tab1);
tabHost.addTab(tab2);
tabHost.addTab(tab3);*/
|
正确代码: 注意:三个及三个选项卡TabWidget,就要用下面的代码,用上面的代码会报错。 TabHost tabHost = this.getTabHost(); View view1 = View.inflate(this, R.layout.tab1_layout, null);
tabHost.addTab(tabHost.newTabSpec("tab1").setIndicator(view1)
.setContent(new Intent(this, Test1Activity.class)));
View view2 = View.inflate(this, R.layout.tab2_layout, null);
tabHost.addTab(tabHost.newTabSpec("tab2").setIndicator(view2)
.setContent(new Intent(this, Test2Activity.class)));
View view3 = View.inflate(this, R.layout.tab3_layout, null);
tabHost.addTab(tabHost.newTabSpec("tab3").setIndicator(view3)
.setContent(new Intent(this, Test3Activity.class))); |