android - How can i use fragment xml tag in layout for another fragment? -
android - How can i use fragment xml tag in layout for another fragment? -
i'm trying 3 page contains list fragment in activity. of pages fragment(from v4 back upwards library) need list fragment within them. when tried have encountered problem(viewpager gives error if turn page) have done research , learned there can not fragment(i mean xml fragment tag not adding dynamically nested fragment) in fragment. instance, in lastly android update of whatsapp there 3 page in 1 activity , 1 of them has list fragment(chat list) wonder how whatsapp have done that? thanks.
my xml layout contains list fragment:
<relativelayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent" android:layout_height="match_parent" > <textview android:id="@+id/textview1" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_alignparenttop="true" android:layout_centerhorizontal="true" android:layout_margintop="17dp" android:text="welcome newsfeed" /> <button android:id="@+id/nfbutton1" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_alignparentbottom="true" android:layout_centerhorizontal="true" android:layout_marginbottom="52dp" android:text="@string/signout" /> <linearlayout android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_below="@+id/textview1" android:layout_centerhorizontal="true" android:layout_centervertical="true" android:orientation="vertical" > <android.support.v4.widget.swiperefreshlayout xmlns:android="http://schemas.android.com/apk/res/android" android:id="@+id/swipe_container" android:layout_width="match_parent" android:layout_height="match_parent"> <fragment android:id="@+id/nflistfragment" android:name="com.comp.buzz.newsfeed.nfquestionfragment" android:layout_width="match_parent" android:layout_height="match_parent" android:gravity="center_horizontal" tools:layout="@layout/item_question" /> </android.support.v4.widget.swiperefreshlayout> </linearlayout>
oncreativeview method of main fragment:
@override public view oncreateview(layoutinflater inflater, viewgroup container, bundle savedinstancestate) { view = inflater.inflate(r.layout.activity_newsfeed, container, false); fragment fragment = new listfragment(); fragmenttransaction transaction = getchildfragmentmanager().begintransaction(); transaction.add(r.id.swipe_container, fragment).commit(); homecoming view; }
you can nest fragments few restrictions (according doc):
android 4.2 or higher you can nest them programmaticallyupdate 1 should job:
fragment fragment = new yourfragment(); fragmenttransaction transaction = getchildfragmentmanager().begintransaction(); transaction.add(r.id.swipe_container, fragment).commit();
android android-fragments android-viewpager android-listfragment
Comments
Post a Comment