How to swap fragments with different layouts in android?

I am developing an Android application using fragments that are more of a Master / Detail form. I want the main action to consist of a list fragment on the left, depending on the element selected on the left. I want to display a fragment with a different arrangement on the right side. (Note: each fragment on the right requires different layouts / views)

All the examples I came across use only one common fragment on the right, changing some values ​​in it or replacing / replacing new fragments having the same layout.

If someone can shed light on this problem, it will help me immensely. Thank!

+5
source share
1 answer

framelayouts , , . ( ) .

XML, ( ).

main.xml

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@+id/frames"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:layout_above="@id/hline1"
    android:layout_below="@id/horizontalline"
    android:orientation="horizontal" >
    <FrameLayout
        android:id="@+id/leftpane"
        android:layout_width="0px"
        android:layout_height="match_parent"
        android:layout_weight=".4" />
    <TextView
        android:id="@+id/verticalline"
        android:layout_width="2dp"
        android:layout_height="match_parent"
        android:background="@color/bar_background"
        android:gravity="center_horizontal"
        android:paddingLeft="5dip"
        android:paddingRight="5dip" />
    <FrameLayout
        android:id="@+id/rightpane"
        android:layout_width="0px"
        android:layout_height="match_parent"
        android:layout_weight="1" >
    </FrameLayout>
</LinearLayout>

id framelayout , .

EventListFragment eventlist = new EventListFragment();
getFragmentManager().beginTransaction().replace(R.id.leftpane, eventlist).commit();

EventDetailFragment eventadd = new EventDetailFragment();
getFragmentManager().beginTransaction().replace(R.id.rightpane, eventadd).commit();

, ( / , , , ):

EventSuperDetailFragment eventsuper = new EventSuperDetailFragment();
getFragmentManager().beginTransaction().replace(R.id.rightpane, eventsuper).commit();
+9

All Articles