java - Android - Nesting Fragments No View Found -
i have 3 fragments , arranged shown below:
"frag , frag c not connected, frag b , c are. each fragment contains 1 listview every time triggered event go next fragment."
fragment ---> (inside frag
a
)fragment b ---> (inside fragb
)fragment c
- fragment a(main.xml)
- fragment b(r.id.contentfragment)
- fragment c(r.id.contentfragment)
i can display fragment , fragment b , okay, but if call fragment c b
i got "no view found in contentfragment=0x7f040039"
.
main.xml
<?xml version="1.0" encoding="utf-8"?> <framelayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="fill_parent" android:layout_height="fill_parent" android:orientation="vertical" android:background="@color/white" android:id="@+id/framelayout" > <listview android:id="@android:id/list" android:layout_width="fill_parent" android:layout_alignparenttop="true" android:layout_alignparentbottom="true" android:layout_height="wrap_content" > </listview> <framelayout android:id="@+id/contentfragment" android:layout_width="fill_parent" android:layout_height="fill_parent" android:layout_weight="1" > </framelayout> </framelayout> </framelayout>
fragmenta.java
inside fragment open fragment b
fragment fragment1 = new fragmentb(); fragmenttransaction transaction = getchildfragmentmanager().begintransaction(); transaction.replace(r.id.contentfragment, fragment1, fragmaingroups ); transaction.addtobackstack(fragmaingroups); transaction.commit();
fragmentb.java
inside fragment b open fragment c
string fraggroups = "groups"; fragment fragment1 = new fragmentc(); fragmenttransaction transaction = getchildfragmentmanager().begintransaction(); transaction.replace(r.id.contentfragment, fragment1, fraggroups ); transaction.addtobackstack(fraggroups); transaction.commit();
fragmentc.java
inside fragment c
public class fragmentitems extends listfragment{ public void onattach(activity activity) { super.onattach(activity); } public void onactivitycreated(bundle savedinstancestate) { super.onactivitycreated(savedinstancestate); } public void oncreate(bundle e) { super.oncreate(e); } @override public view oncreateview(layoutinflater inflater, viewgroup container, bundle savedinstancestate) { view rootview = inflater.inflate(r.layout.load_items_activity, container, false); return rootview; } }
logcat
07-25 18:10:20.388: e/fragmentmanager(24703): no view found id 0x7f040039 (com.jinisys.restoplusordering:id/contentfragment) fragment fragmentitems{4156f480 #0 id=0x7f040039 groups} 07-25 18:10:20.388: e/fragmentmanager(24703): activity state: 07-25 18:10:20.388: e/fragmentmanager(24703): no view found id 0x7f040039 (com.jinisys.restoplusordering:id/contentfragment) fragment fragmentitems{4156f480 #0 id=0x7f040039 groups} 07-25 18:10:20.388: e/fragmentmanager(24703): activity state: 07-25 18:10:20.718: e/androidruntime(24703): fatal exception: main 07-25 18:10:20.718: e/androidruntime(24703): java.lang.illegalargumentexception: no view found id 0x7f040039 (com.jinisys.restoplusordering:id/contentfragment) fragment fragmentitems{4156f480 #0 id=0x7f040039 groups} 07-25 18:10:20.718: e/androidruntime(24703): @ android.support.v4.app.fragmentmanagerimpl.movetostate(fragmentmanager.java:903) 07-25 18:10:20.718: e/androidruntime(24703): @ android.support.v4.app.fragmentmanagerimpl.movetostate(fragmentmanager.java:1088) 07-25 18:10:20.718: e/androidruntime(24703): @ android.support.v4.app.backstackrecord.run(backstackrecord.java:682) 07-25 18:10:20.718: e/androidruntime(24703): @ android.support.v4.app.fragmentmanagerimpl.execpendingactions(fragmentmanager.java:1444) 07-25 18:10:20.718: e/androidruntime(24703): @ android.support.v4.app.fragmentmanagerimpl$1.run(fragmentmanager.java:429) 07-25 18:10:20.718: e/androidruntime(24703): @ android.os.handler.handlecallback(handler.java:615)
as error states looking view id contentfragmentttems
inside fragment b, main view contentfragment
, not whole main.xml
. if want add new fragment should fragment a.
Comments
Post a Comment