我有一个listview withcin活动,当有人点击时 在listview中的项目上,我想要开始一个类型的活动 TabActivity。
关于它为什么不起作用的任何想法?
list.setOnItemClickListener(new OnItemClickListener() {
public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
JobListRowData item = jobListAdapter.getItem(position);
Intent myIntent = new Intent(view.getContext(), EventsTabs.class);
startActivity(myIntent);
} } });
public class EventsTabs extends TabActivity {
private TabHost mTabHost;
@Override
public void onCreate(Bundle savedInstanceState) {
setContentView(R.layout.event_main);
Resources res = getResources();
TabHost tabHost = getTabHost();
TabHost.TabSpec spec;
Intent intent;
intent = new Intent().setClass(this, EventsTabs.class);
spec = tabHost.newTabSpec("artists").setIndicator("Artists", res.getDrawable(R.drawable.icon)).setContent(intent);
tabHost.addTab(spec);
intent = new Intent().setClass(this, EventsTabs.class);
spec = tabHost.newTabSpec("albums").setIndicator("Albums",res.getDrawable(R.drawable.icon)).setContent(intent);
tabHost.addTab(spec);
intent = new Intent().setClass(this, EventsTabs.class);
spec = tabHost.newTabSpec("songs").setIndicator("Songs", res.getDrawable(R.drawable.icon)).setContent(intent);
tabHost.addTab(spec);
tabHost.setup();
}
}
出于某种原因,我得到了: 12-06 13:37:47.607:ERROR / AndroidRuntime(346):引起:java.lang.IllegalStateException:在创建包含组之前,无法添加活动。
答案 0 :(得分:0)
尝试将此添加到您的代码中..
LocalActivityManager mlam = new LocalActivityManager(this, false);
mlam.dispatchCreate(savedInstanceState);
tabHost.setup(mlam );
编辑:你应该在向它添加标签之前设置tabhost ..
您应该首先调用设置......
TabHost tabHost = getTabHost();
TabHost.TabSpec spec;
tabHost.setup(); //Move set up here
Intent intent;
intent = new Intent().setClass(this, EventsTabs.class);
spec = tabHost.newTabSpec("artists").setIndicator("Artists", res.getDrawable(R.drawable.icon)).setContent(intent);
tabHost.addTab(spec);
intent = new Intent().setClass(this, EventsTabs.class);
spec = tabHost.newTabSpec("albums").setIndicator("Albums",res.getDrawable(R.drawable.icon)).setContent(intent);
tabHost.addTab(spec);
intent = new Intent().setClass(this, EventsTabs.class);
spec = tabHost.newTabSpec("songs").setIndicator("Songs", res.getDrawable(R.drawable.icon)).setContent(intent);
tabHost.addTab(spec);