Calling a dialog function from an action bar item crashes Android app

[postlink] https://the-best-way-of-life-is-islam.blogspot.com/2015/07/calling-dialog-function-from-action-bar.html [/postlink]

I have an action bar item that I would like to click which I set:

android:onClick="showDialog"

So I can call my show dialog function which works fine when called from a button on my activity_main.xml but not from my menu_main.xml. When I enter this code in menu_main.xml I get this small informational warning, -- Method "showDialog" in "MainActivity" has an incorrect signature.

As soon as the app opens up, it instantly crashes with a 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 is my showDialog code in the MainActivity:

    public void showDialog(View v){
        FragmentManager Fmanager = getFragmentManager();
        Dialog myDialog = new Dialog();
        myDialog.show(Fmanager, "MyDialog");
}

Here is my 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 is my 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"/>

اذا أعجبك الموضوع ساهم في نشره :

Enregistrer un commentaire

 
حقوق النشر: Published by | Template Created by | القناة على اليوتيب
copyright © 2014. The Best Way Of Life Is Islam -يمكن نقل كل ما هو موجود في موقع الرحمة تيوب
القرآن الكريم و الأحاديث النبوية أناشيد و دروس اسلامية منوعة موقع الفيديوهات الاسلامية
تطوير و تعريب مدونة ثعلوب