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?
android:onClick
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
You need to add two properties:
android:clickable="true" android:onClick="yourFunctionName"
This will not work unless you add android:clickable="true"
android:clickable="true"
Source: https://habr.com/ru/post/1796702/More articles:How to create an instance of a database object to be used in other classes? - variablesHow to use "disableAlpha" using EditText / How to change attribute in AttributeSet - androidJTable padding using one object per line - javaProblem with SQL query - functionConverting a string representing a list into an actual list object - pythonone-dimensional (deep) scaling with a changing aspect ratio - ratioList of UITextField? How to achieve a similar interface? - iosC ++: fixing binary using fstream - c ++Change wallpaper in Windows 7 - windows-7Insert a new node at the top of the Linked-List - cAll Articles