0

I'm new to the android framework and I wonder if it is possible to call the same activity from a TabHost? I have 3 tabs and every tab populate a list but different values. I want to filter the list in the tabs. Every tab's data build from the list, that's why I don't want to make 3 different Activity. It is possible with the TabHost and TabActivity classes?

Thanks in advance!

Br, Peter

hcpeter
  • 614
  • 3
  • 11
  • 24

2 Answers2

0

Example of using Android tabs with Views instead of Activities?

One way to do it is create the three tabs each using the same content layout (something with a listview) and then whenever the user changes tab (register OnTabChangedListener). Clear the current list view and reload it with your new data. The OnTabChangedListener will also tell you which tab it switched to.

Community
  • 1
  • 1
jsb
  • 329
  • 1
  • 11
0

You should be able to specify the same Activity for each tab. To have it filter, I would just send along a Extra value on the intent.

Something like this:

public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.tab_host_layout);

    TabHost tabHost = getTabHost();

    Intent intent1 = new Intent(this, MyActivity.class);
    intent1.putExtra("filter", 1);
    tabHost.addTab(tabHost.newTabSpec("tab1")
            .setIndicator("Tab1")
            .setContent(intent1));

    Intent intent2 = new Intent(this, MyActivity.class);
    intent2.putExtra("filter", 2);
    tabHost.addTab(tabHost.newTabSpec("tab2")
            .setIndicator("Tab2")
            .setContent(intent2));

}
Ross Hambrick
  • 5,880
  • 2
  • 43
  • 34