David K.
David K.

Reputation: 6371

Android custom dialog button XML onClick error

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?

Upvotes: 3

Views: 5006

Answers (2)

user5104628
user5104628

Reputation:

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"

Upvotes: 0

Hostile
Hostile

Reputation: 489

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

Upvotes: 5

Related Questions