android - ListFragment Replace "addView(View) is not supported in AdapterView" after switching from SupportFragmentManager to FragmentManager -


i have activity has fragment. when click on list item current fragment gets replaced fragment. used work correctly...

however, move away supportfragmentmanager fragmentmanager...i no longer support old android versions.

when made switch app started crashing above error. here full stacktrace...

05-06 05:24:35.868: e/androidruntime(1381): fatal exception: main 05-06 05:24:35.868: e/androidruntime(1381): java.lang.unsupportedoperationexception: addview(view) not supported in adapterview 05-06 05:24:35.868: e/androidruntime(1381):     @ android.widget.adapterview.addview(adapterview.java:445) 05-06 05:24:35.868: e/androidruntime(1381):     @ android.app.fragmentmanagerimpl.movetostate(fragmentmanager.java:839) 05-06 05:24:35.868: e/androidruntime(1381):     @ android.app.fragmentmanagerimpl.movetostate(fragmentmanager.java:1032) 05-06 05:24:35.868: e/androidruntime(1381):     @ android.app.backstackrecord.run(backstackrecord.java:622) 05-06 05:24:35.868: e/androidruntime(1381):     @ android.app.fragmentmanagerimpl.execpendingactions(fragmentmanager.java:1382) 05-06 05:24:35.868: e/androidruntime(1381):     @ android.app.fragmentmanagerimpl$1.run(fragmentmanager.java:426) 05-06 05:24:35.868: e/androidruntime(1381):     @ android.os.handler.handlecallback(handler.java:605) 05-06 05:24:35.868: e/androidruntime(1381):     @ android.os.handler.dispatchmessage(handler.java:92) 05-06 05:24:35.868: e/androidruntime(1381):     @ android.os.looper.loop(looper.java:137) 05-06 05:24:35.868: e/androidruntime(1381):     @ android.app.activitythread.main(activitythread.java:4424) 05-06 05:24:35.868: e/androidruntime(1381):     @ java.lang.reflect.method.invokenative(native method) 05-06 05:24:35.868: e/androidruntime(1381):     @ java.lang.reflect.method.invoke(method.java:511) 05-06 05:24:35.868: e/androidruntime(1381):     @ com.android.internal.os.zygoteinit$methodandargscaller.run(zygoteinit.java:784) 05-06 05:24:35.868: e/androidruntime(1381):     @ com.android.internal.os.zygoteinit.main(zygoteinit.java:551) 05-06 05:24:35.868: e/androidruntime(1381):     @ dalvik.system.nativestart.main(native method) 

this change made , confused.

here key snippets of code:

activity:

fragment2 mfragment2 = new fragment2(); fragmenttransaction transaction = getfragmentmanager().begintransaction(); transaction.replace(r.id.listfragment1, mfragment2 , fragment2_fragment_tag); transaction.addtobackstack(null); transaction.commit(); 

fragment2:

@override     public view oncreateview(layoutinflater inflater, viewgroup container,             bundle savedinstancestate) {          view fragment2= inflater.inflate(r.layout.list_fragment2,                 container, false);          return fragment2;     } 

xml:

activity:

<?xml version="1.0" encoding="utf-8"?> <relativelayout xmlns:android="http://schemas.android.com/apk/res/android"     android:id="@+id/listactivity"     android:layout_width="match_parent"     android:layout_height="match_parent"     android:orientation="horizontal"      android:background="@drawable/lists_background"     android:divider="@color/black">     <textview         android:id="@+id/list_header_text"         android:layout_width="match_parent"         android:layout_height="wrap_content"         android:layout_alignparenttop="true"         android:layout_centerhorizontal="true"         android:textsize="20sp"         android:textcolor="@color/black"         android:textstyle="bold"/>    <fragment         android:id="@+id/listfragment1"         android:layout_width="match_parent"         android:layout_height="match_parent"         android:layout_below="@+id/list_header_text"         android:layout_centerhorizontal="true"         class="com.test.fragment1"         android:tag="fragment1" />   </relativelayout> 

fragment2:

<?xml version="1.0" encoding="utf-8"?> <listview xmlns:android="http://schemas.android.com/apk/res/android"         android:layout_width="fill_parent"         android:layout_height="fill_parent"         android:id="@android:id/list"         android:listselector="@android:color/transparent"         android:background="@drawable/lists_background"         android:divider="@color/black"         android:dividerheight="1dip"         android:clickable="true"> </listview> 

thank , let me know if need more info or details.

fragments going used in transactions shouldn't placed in xml layout. instead container layout should used fragments being added container.

to avoid addview() exception wrap listview in layout, don't know why happens seems framework calls addview()(which not implemented children of adapterview) method when fragments it's being rebuilt.


Comments