Tabs Using Fragments On Android, But Inside Another Layout
Solution 1:
Ideally this would be done using nested Fragments, but Android doesn't support that yet. That leaves the deprecated ActivityGroup class. You'll need a top level activity that extends ActivityGroup and launches the two activities.
Here is how you launch the activities and get their views:
finalWindoww= getLocalActivityManager().startActivity(myTag, myIntent);
finalViewwd= w != null ? w.getDecorView() : null;
if ( null != wd ) {
wd.setVisibility(View.VISIBLE);
wd.setFocusableInTouchMode(true);
}
// TODO: Attach wd to a ViewGroup.
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ Edit: Below is a more complete solution.
This is the layout for the top level activity:
<?xml version="1.0" encoding="utf-8"?><LinearLayoutxmlns:android="http://schemas.android.com/apk/res/android"android:id="@+id/root_layout"android:layout_width="match_parent"android:layout_height="match_parent"android:orientation="vertical"
></LinearLayout>
Here is the top level class:
publicclassEmbeddedActivityParentextendsActivityGroup {
private LinearLayout mRootLayout;
@OverrideprotectedvoidonCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
mRootLayout = (LinearLayout) findViewById(R.id.root_layout);
// Add embedded status activity.
embedActivity("StatusColumn", newIntent(this, StatusActivity.class));
// Add embedded work activity.
embedActivity("WorkArea", newIntent(this, MainActivity.class));
}
privatevoidembedActivity(String myTag, Intent launchIntent) {
finalWindoww= getLocalActivityManager().startActivity(myTag, launchIntent);
finalViewwd= w != null ? w.getDecorView() : null;
if ( null != wd ) {
wd.setVisibility(View.VISIBLE);
wd.setFocusableInTouchMode(true);
mRootLayout.addView(wd);
}
}
}
You can add as many embedded activities as you want. You can even nest embedded activities, but be aware that performance could become a factor. We use this to support a dynamic status column.
Personally, I think there is still a use for the ActivityGroup and hope that Gooogle changes their mind about deprecating it.
Post a Comment for "Tabs Using Fragments On Android, But Inside Another Layout"