2012-01-20 18 views
3

我有一個自定義的TabView,它顯示ListActivity,但每次點擊其中一個列表項時,就會導致新的活動並且TabView完全消失。Android:使新的活動停留在標籤內

我想要的是,當我點擊列表中的某個項目時,顯示的新活動仍然保留在選項卡內。

任何人都可以幫助我改進我的代碼嗎?

這裏是我的自定義代碼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; 
} 

,這是從ListActivity的代碼onListItemClick片段:

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); 

回答