I have a custom dialog with some buttons and I would like to set the click handlers for the buttons from within the XML file with android:onClick
attribute but whenever I set this attribute my application crashes when I click on the buttons within the dialog. The error is something along the开发者_开发技巧 lines of not being able to find the method within the context. Has anyone gotten dialog click handler to work from within the XML file or do I have to define the click handler when I create the dialog?
If I understand your question correctly, you should be able to extend the Dialog class to do what you want, as in Jett's answer here: Using onClick attribute in layout xml causes a NoSuchMethodException in Android dialogs
You need to add two properties:
android:clickable="true"
android:onClick="yourFunctionName"
It won't work, if you don't add the android:clickable="true"
精彩评论