mono - Crash during Fragment transactions inside the Custom Dialog in Xamarin Android -
when tried add fragment inside dialog, app got crash. crash saying "no view found id 0x01276"
this layout file dialog (my_dialog_layout.axml)
<?xml version="1.0" encoding="utf-8"?> <linearlayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="fill_parent" android:layout_height="fill_parent" android:orientation="vertical" > <linearlayout android:id="@+id/fragment_container" android:layout_width="wrap_content" android:layout_height="wrap_content" /> </linearlayout>
and code opening dialog , fragment transaction
class customdialog : dialog{ public override void oncreate(bundle savedinstancestate) { base.oncreate(savedinstancestate) setcontentview(resource.layout.dialog_fragment_layout); var mycustomfragmnent = new mycustomfragment(_context); // start fragment transaction process var transaction = fragmentmanager.begintransaction(); // here crash saying (no view found id 0x01276....) transaction.add(resource.id.fragment_container, mycustomfragmnent); transaction.commit(); } }
firstly don't need use "heavy" layout such linearlayout
, suggest use framelayout
container.
secondly, try use transaction.replace
instead. make sure mycustomfragment
not blow in oncreateview
. might problem lies didn't post full stack trace.
when using transaction.replace
can have handle backstack adding:
transaction.addtobackstack(null);
after replace
call, such when press button on phone navigates previous fragment
shown.
Comments
Post a Comment