Calling a dialog function from an action bar item crashes Android app -
i have action bar item click set:
android:onclick="showdialog"   so can call show dialog function works fine when called button on activity_main.xml not menu_main.xml. when enter code in menu_main.xml small informational warning, -- method "showdialog" in "mainactivity" has incorrect signature.
as app opens up, instantly crashes fatal exception:
dialog.com.dialogtry1 e/androidruntime﹕ fatal exception: main android.view.inflateexception: couldn't resolve menu item onclick handler showdialog in class dialog.com.dialogtry1.mainactivity
here showdialog code in mainactivity:
    public void showdialog(view v){         fragmentmanager fmanager = getfragmentmanager();         dialog mydialog = new dialog();         mydialog.show(fmanager, "mydialog"); }   here dialog class:
    public class dialog extends dialogfragment{         @nullable         @override         public view oncreateview(layoutinflater inflater, viewgroup container,              bundle savedinstancestate) {         return inflater.inflate(r.layout.dialogfragment, null);     } }   here dialogfragment.xml:
<textview     android:layout_width="wrap_content"     android:layout_height="wrap_content"     android:text="create new list."     android:id="@+id/headerid"     android:textsize="20sp"     android:padding="5dp"     android:layout_alignparenttop="true"     android:layout_alignparentleft="true"/> <edittext     android:layout_width="wrap_content"     android:layout_height="wrap_content"     android:hint="list name here."     android:layout_below="@+id/headerid"     android:id="@+id/edittextid"/> <button     android:layout_width="wrap_content"     android:layout_height="wrap_content"     android:text="yes"     android:layout_below="@+id/edittextid"     android:id="@+id/yesid"/> <button     android:layout_width="wrap_content"     android:layout_height="wrap_content"     android:text="no"     android:id="@+id/noid"     android:layout_below="@+id/edittextid"     android:layout_torightof="@+id/yesid"/>        
instead of using
android:onclick="showdialog"   try using onoptionsitemselected explained here. onoptionsitemselected correct way handle click events in menu items.
Comments
Post a Comment