3

I have a customized TabView which displays a ListActivity, but everytime I click one of the list item, it leads to a new activity and the TabView is completely gone.

What I want is, when I click one of the item on the list, the new activity is displayed and still stays inside the tab.

Can anybody help me improve my code?

Here's my code for the customized 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;
}

and this is the onListItemClick snippet from the ListActivity's code:

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);
hectichavana
  • 1,436
  • 13
  • 41
  • 71

1 Answers1

2

What you are looking for is Activity Groups. Here are few examples which will get you started with it.

ActivityGroup Example

Android: ActivityGroup tutorial with example

http://gamma-point.com/content/android-how-have-multiple-activities-under-single-tab-tabactivity

http://www.devdaily.com/java/jwarehouse/android/core/java/android/app/ActivityGroup.java.shtml

Community
  • 1
  • 1
Andro Selva
  • 53,910
  • 52
  • 193
  • 240