views:

200

answers:

2

Following situation: I have TabActivity with e.g. three tabs, TabA, TabB, TabC.

There are a button in activity (Act_C_1) of TabC. So if the user clicks on that button, another activity (Act_C_2) should occur in TabC.

I thank you in advance for any suggestions / or ideas.

Mur

UPD:

Here is my code

TabActivity with three Activities:

public class TabScreen extends TabActivity
{
    public void onCreate(Bundle savedInstanceState) 
    {
        super.onCreate(savedInstanceState);

        setContentView(R.layout.tab_menu);

        TabHost tabHost = getTabHost();  // The activity TabHost
        TabHost.TabSpec spec;  // Resusable TabSpec for each tab
        Intent intent;  // Reusable Intent for each tab

        intent = new Intent().setClass(this, SecondActivity.class);

        // Initialize a TabSpec for each tab and add it to the TabHost
        spec = tabHost.newTabSpec("tab_1").setIndicator("Tab1",null).setContent(intent);
        tabHost.addTab(spec);

        intent = new Intent().setClass(this, ThirdActivity.class);
        // Initialize a TabSpec for each tab and add it to the TabHost
        spec = tabHost.newTabSpec("tab_2").setIndicator("Tab2",null).setContent(intent);
        tabHost.addTab(spec);

        intent = new Intent().setClass(this, FourthActivity.class);
        spec = tabHost.newTabSpec("tab_3").setIndicator("Tab3",null).setContent(intent);
        tabHost.addTab(spec);
    }

}

Activity 'Act_C_1' or FourthActivity.java:

public class FourthActivity extends Activity implements OnClickListener
{
    public void onCreate(Bundle savedInstanceState) 
    {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.fourth);

        Button BtnWeiter = (Button)findViewById(R.id.BtnWeiter);
        BtnWeiter.setOnClickListener(this);
    }

    @Override
    public void onClick(View v) 
    {                    
        // I also tried to use LocalActivityManager
        // TabActivity parentTabActivity = (TabActivity) getParent();            
        // LocalActivityManager manager = parentTabActivity.getLocalActivityManager();
        // manager.destroyActivity("tab_3", true);
        // manager.startActivity("tab_3", new Intent(this, FourthActivity.class));
        finish();
        startActivity(new Intent(this, FourthActivity.class));            
    }        
}
A: 

Handle the onClick event for button

finish() the activity Add startActivity method to start another activity.

Thanks

success_anil
Nice suggestion, but that doesn't work by TabActivity ... at least by me.
Mur Votema
Hi Please post your code snippet... I will try editing it.
success_anil
I included important part of my code. 'Doesn't work' isn't right, but if I do it on that way, the tab activity will be finished. What I want to have, that just an activity within tabactivity will be finished and another one will be start within tab.
Mur Votema
Hmm .. I 'm not against your application design... As far as i know if you want to achieve the same effect... use buttons that will look like tabs and then you will have the full control on which activity you should start or finish. Tabs work in that way only that if you try to invoke new activity from the activity getting displayed inside the tab, the new activity will take up the whole screen even the tabs too.
success_anil
A: 

This tutorial will help you in dealing with a tabactivity and nested activities.

yann.debonnel