0

I want to change the content of a tab? when tha tab is created i set the content of the tab by setContent() method. But if I click again, I want to change the content that means change to another activity.

I used setOnTabChangedListener() method, but I am not sure about how to set the content to another intent?

 Resources res = getResources();
 TabHost tabHost=getTabHost();
 tabHost.addTab(tabHost.newTabSpec("tab1").setIndicator("HOME").setContent(new Intent(getBaseContext(),homeGroup.class)));
 tabHost.addTab(tabHost.newTabSpec("tab2").setIndicator("ABOUT US").setContent(new Intent(getBaseContext(),aboutusGroup.class)));
 tabHost.setCurrentTab(0);

 tabHost.setOnTabChangedListener(new OnTabChangeListener()
 {  
     @Override
     public void onTabChanged(String tabId)
     {
        //here i want to set the content of each tab to another intent

               // for 'tab1', change to home.class
               // for 'tab2', change to aboutus.class
     //how to set these?                

     }
 });

Please help me.. Thank you..

Jomia
  • 3,414
  • 10
  • 46
  • 63

2 Answers2

1

I got solution from the following link :

android tabwidget intent tabs refresh every hit

Sorry for disturbing..

Community
  • 1
  • 1
Jomia
  • 3,414
  • 10
  • 46
  • 63
0

You need not to change the content of your activity in a Tab for accommodating new Activity Content.

Instead you need to use ActivityGroup .

Check the link here

Changing the view within the Android Tab Widget

http://ericharlow.blogspot.com/2010/09/experience-multiple-android-activities.html

Hope it helps :)

Community
  • 1
  • 1
Rohit Sharma
  • 13,787
  • 8
  • 57
  • 72
  • my requirement is when i click on the tab, it should load an intent. I have used ActivityGroup in my application, so that, it will load another and another activities. But when I click on the home tab again, i want to load the first activity itself. – Jomia Feb 21 '11 at 10:14
  • in the activity group there is a stack of activity is maintained. on tab click get each actvity from that stack call finish on each till you reach the first one. – Rohit Sharma Feb 21 '11 at 10:21