我有一个显示TabView
的自定义ListActivity
,但每次点击其中一个列表项时,都会导致新的活动,并且TabView完全消失。
我想要的是,当我点击列表中的某个项目时,会显示新活动并仍然保留在标签内。
有人可以帮我改进我的代码吗?
以下是我自定义TabView
的代码:
super.onCreate(savedInstanceState);
// construct the tabhost
setContentView(R.layout.project_tab);
setupTabHost();
setupTabL(new TextView(this), "Alle", (ProjectsList.class));
setupTab(new TextView(this), "Kategorien", (CategoryList.class));
setupTabR(new TextView(this), "Favorites", (ProjectsList.class));
final Button refresh = (Button) findViewById(R.id.btn_project_refresh);
refresh.setOnClickListener(refresh_listener);
}
private void setupTab(final View view, final String tag, final Class<?> context) {
View tabview = createTabView(mTabHost.getContext(), tag);
TabSpec ts1 = mTabHost.newTabSpec("tab1");
ts1.setIndicator(tabview);
mTabHost.addTab(ts1);
}
private static View createTabView(final Context context, final String text) {
View view = LayoutInflater.from(context).inflate(R.layout.inner_tab_m_bg, null);
TextView tv = (TextView) view.findViewById(R.id.tabsText);
tv.setText(text);
return view;
}
这是onListItemClick
代码中的ListActivity
代码段:
protected void onListItemClick(ListView l, View v, int position, long id) {
super.onListItemClick(l, v, position, id);
Object o = this.getListAdapter().getItem(position);
String choice = o.toString();
if (choice .equals("Entwicklungshilfe")) {
Intent i = new Intent(CategoryList.this, SubCategoryList.class);
i.putExtra("category","'%Entwicklungshilfe%'");
startActivityForResult(i,0);
答案 0 :(得分:2)