android tabs - starting a new activity

前端 未结 5 602
迷失自我
迷失自我 2021-01-13 22:14

There are 4 Tabs in a TabHost, let them be A, B, C, and D. Now each one is just an index page and clicking on any of them shows a different activity.

The problem is

5条回答
  •  心在旅途
    2021-01-13 23:14

    To summarize the link that Rukmal Dias provided. Here's what you do:

    1. Change your current Activity (that's in a tab) to derive from ActivityGroup
    2. Create a new intent for the Activity you want to switch to
    3. Copy/Paste and call this function in your current activity where "id" is the "android:id" for the layout of the new activity you want to switch to

       public void replaceContentView(String id, Intent newIntent){
            View view = getLocalActivityManager().startActivity(id,newIntent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP)) .getDecorView(); 
            this.setContentView(view);}
      

    Here's an example of how I make the call to switch views from my current Tabbed Activity:

    public void switchToNextActivity(View view)
    {
        Intent myIntent = new Intent(getApplicationContext(), MyNextActivity.class);
        replaceContentView("next_activity", myIntent);
    }
    

提交回复
热议问题