views:

78

answers:

3

In Android, the TabHost object renders activities in a type of inline way. I'm wondering if there's any way I can do a similar type of thing, without using the tab-host. Suppose, i want to have a toolbar or sliding drawer that allows me to switch between the activities in the same way that the TabHost does this. In other words, I'd like to render an activity inline inside of another activity, sort of like an iframe for activities...

A: 

This may not be exactly loading separate Activities, but...

Instead of Activities, you could achieve that functionality from a user's perspective by by dynamically loading layouts inside a single Activity. That way you could have a slider and update the layout(s) on screen as needed.

Ryan Hayes
yes, but then i'd have to have logic for each view. suppose i have like 10 different views, now all of a sudden i have to have a big switch statement that would determine which layout to show and all the logic to render it. putting each one into its own activity would be a nice way to separate things out into their own logical place... basically like the way TabHost works... except not using tabhost... :)
Ben
Haha, well, it's going to be a hack whatever you do, since the best practice is to use the provided tab container to keep your app in a consistent look and feel. Is there a reason you can't use TabHost? Or are you creating an alternative to TabHost for the sole purpose of creating an alternative?
Ryan Hayes
well, we want to be able to 'swipe' between views without having to take up the real-estate involved w/ the tab view.
Ben
Oh, well, in that case, can you make a new Interface for your Activities and add swipe left/right methods that load/unload the next one in the series? Maybe have a property file that maps the series number to the Activity? That way you could add the swipe left/right transitions (the left animation would be like what you see when you hit the back button and it animates back to the last activity) as you load/unload each activity to the left or the right.
Ryan Hayes
hmmm, ok yeah i'll give that a whirl...
Ben
A: 

No and even use of activities in tabs is discouraged in favor of views. You can do other searches here or on the android google groups to read why.

If you must have separate activities you should start them the proper way with Intents and let Android manage their lifecycle or do tabs with a view per tab.

BrennaSoft
A: 

Basically you need to play with LocalActivityManager and the ActvityGroup class:

Suppose you have your DashBoard class:

public class Dashboard extends ActivityGroup implements View.OnClickListener {
  super.onCreate(savedInstanceState);

    //Your view with the activity launcher buttons on the bottom for instance
   setContentView(R.layout.frame);

    @Override
    public void onClick(View v) {


        Intent intent = new Intent().setClassName(context,YourActivity.class);

        intent.setAction(Intent.ACTION_VIEW);


        LocalActivityManager localActivityManager = getLocalActivityManager();


        final Window w = localActivityManager.startActivity("uniqueID", intent);
        final View wd = w != null ? w.getDecorView() : null;

             //the content of your activity goes here
        FrameLayout frameLayout = (FrameLayout) findViewById(R.id.tabcontent);
        frameLayout.removeAllViews();
        frameLayout.addView(wd);
    }

}
Francesco
this sounds VERY promising, i'll give that a whirl and let you know how it goes... thanks!
Ben