Search code examples
androidactivitygroupandroid-actionbargreendroid

android Greendroid ActionBar using ActivityGroup


I'm currently trying to implements a greendroid ActionBar that have a ActivityGroup below it. When the user clicks a button of the actionBar, it will switch to one activity of the groupActivity. I've searched a lot, but I just found some tutos about TabBars and it is not the same, as I am not implement a TabBar so I cant just set the groupActivity when I init the tababr. ActionBar is working with methods called when a button is pushed.

In other words : how to simply manage an ActivityGroup without having a TabBar? And how to print the current Activity below the ActionBar ?

Thanks.


Solution

  • The ActivityGroup will always be your main activity. So in the onCreate of the ActivityGroup you can build your tabs (see: http://developer.android.com/guide/topics/ui/actionbar.html#Tabs). Make sure to add an ActionBar.TabListener to your tabs. Then, in the onTabSelected you can put the code to switch between your activities.

    For example:

    public void onTabSelected(Tab tab, FragmentTransaction ft) 
    {
        // assumed the tabs are created with a tag and that you defined the 
        // tablistener inline, so you have access to the ActivityGroup
        Window window = MyActivityGroup.this.getLocalActivityManager().startActivity(tab.getTag(), intent);
        final View view = window.getDecorView();
        runOnUiThread(new Runnable()
        {
          public void run()
          {
            setContentView(view);
          }
        });
    }
    

    Hope this helps for the tabs in the ActionBar. To show the user the active Activity, of course you have the tabs. Otherwise, you could also set the title of the ActivityGroup using getParent() in the child Activity, like: Activity.getParent().setTitle("child Activity"). Or you could just do something in the child Activity to display something like a title.