4

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?

David K.
  • 5,703
  • 10
  • 44
  • 76

2 Answers2

5

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

Community
  • 1
  • 1
Hostile
  • 489
  • 6
  • 10
0

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"