【发布时间】:2014-04-25 10:15:44
【问题描述】:
我正在使用片段选项卡编写一个简单的选项卡视图(因为不推荐使用 TabActivity)
但是当我尝试运行它时,它会提示错误“您是否忘记调用 'public void setup(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 与 Intent 一起使用...使用这个
addTab(TabHost.TabSpec tabSpec, Class<?> clss, Bundle args)版本的 addTab(请记住,clss 应该是扩展 Fragment 的类) -
我把它改成:listTab.addTab(listTab.newTabSpec("all_post").setIndicator("All"), ListPost.class, null);其中 ListPost 是扩展 ListFragment 但错误仍然相同:(