我寫使用片段標籤(因爲TabActivity已被淘汰)你忘記調用'public void setup(LocalActivityManager activityGroup)'嗎?
一個簡單的標籤視圖但是當我嘗試運行它,它會提醒錯誤「難道你忘了叫‘公共無效設置(LocalActivityManager的ActivityGroup)’? 」。另外我注意到ActivityGroup和setup(void)也被棄用。
如何解決?
public class ListTab extends FragmentActivity{
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.list_tab);
FragmentTabHost listTab = (FragmentTabHost)findViewById(R.id.list_tab_host);
listTab.setup(this, this.getSupportFragmentManager(), R.id.realtabcontent);
TabSpec allPostSpec = listTab.newTabSpec("all_post");
allPostSpec.setIndicator("All");
Intent allPostIntent = new Intent(this,ListPost.class);
allPostSpec.setContent(allPostIntent);
listTab.addTab(allPostSpec);
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.list_post, menu);
return true;
}
@Override
public boolean onOptionsItemSelected(MenuItem item) {
// Handle action bar item clicks here. The action bar will
// automatically handle clicks on the Home/Up button, so long
// as you specify a parent activity in AndroidManifest.xml.
int id = item.getItemId();
if (id == R.id.action_settings) {
return true;
}
return super.onOptionsItemSelected(item);
}
}
如果您正在使用FragmentTabHost不故意使用則tabspec ......用這個'addTab(TabHost.TabSpec則tabspec,類> CLSS,捆綁參數) 'addTab版本(記住clss應該是擴展Fragment的類) – Selvin
我將它更改爲: listTab.addTab(listTab.newTabSpec(「all_post」).setIndicator(「All」),ListPost.class,null); 其中ListPost是擴展ListFragment 但錯誤還是一樣:( – Simon