我有一个 tabhost,我在那里添加了 3 个活动(每个选项卡一个活动)。每次更改选项卡时,我都需要知道如何在活动中调用新实习生。我为 tabhost 添加了一个侦听器。当我使用该clearAllTabs();
方法并在侦听器中再次添加所有选项卡时,应用程序崩溃。当我使用代码从视图中删除用户单击的特定选项卡时tabHost.getTabWidget().removeView(tabHost.getTabWidget().getChildTabViewAt(i));
tabHost.addTab(the tab I want to replace);
然后新标签位于标签主机的末尾。
我只需要一个示例,说明每次用户单击特定选项卡时如何重新加载比例活动。
我的代码:
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
// ActionBar bar = getSupportActionBar();
// requestWindowFeature(Window.FEATURE_NO_TITLE);
setContentView(R.layout.activity_main);
Resources res = getResources();
LocalActivityManager mlam = new LocalActivityManager(this, false);
final TabHost tabHost = (TabHost) findViewById(android.R.id.tabhost);
mlam.dispatchCreate(savedInstanceState);
tabHost.setup(mlam);
TabHost.TabSpec spec;
Intent intent;
// TabHost tabHost = getTabHost();
// tabHost.setup();
TabSpec specAll = tabHost.newTabSpec("All");
specAll.setIndicator("All");
Intent allIntent = new Intent(this, allActivity.class);
specAll.setContent(allIntent);
// specAll.setContent(R.id.allList);
Log.d("SpecAll",""+specAll.setContent(allIntent));
TabSpec specIn = tabHost.newTabSpec("in");
specIn.setIndicator("In");
Intent inIntent = new Intent(this, inActivity.class);
specIn.setContent(inIntent);
TabSpec specOut = tabHost.newTabSpec("Out");
specOut.setIndicator("Out");
Intent outIntent = new Intent(this, outActivity.class);
specOut.setContent(outIntent);
// Adding all TabSpec to TabHost
tabHost.addTab(specAll); // Adding all tab
tabHost.addTab(specIn); // Adding in tab
tabHost.addTab(specOut); // Adding out tab
tabHost.setOnTabChangedListener(new OnTabChangeListener() {
@Override
public void onTabChanged(String tabId) {
int i = tabHost.getCurrentTab();
//Log.i("@@@@@@@@ ANN CLICK TAB NUMBER", "------" + i);
if (i == 0) {
Log.d("TAB","" +i);
} else if (i == 1) {
Log.d("TAB","" +i);
}
else
Log.d("TAB", ""+i);
}
});
}