Android XML Custom Dialog Button onClick error

I have a user dialog with some buttons, and I would like to set click handlers for buttons from an XML file with an attribute android:onClick, but whenever I set this attribute, my application crashes when I click the buttons within the dialog. The error is that it cannot find the method in context. Has anyone got a dialog handler for working from an XML file, or do I need to define a click handler when creating a dialog?

+3
source share
2 answers

If I understand your question correctly, you should extend the Dialog class to do what you want, as in Jett's answer: Using the onClick attribute in the xml layout throws a NoSuchMethodException in the Android dialog

+5
source

You need to add two properties:

android:clickable="true"
android:onClick="yourFunctionName"

This will not work unless you add android:clickable="true"

0
source

Source: https://habr.com/ru/post/1796702/


All Articles