user754691
user754691

Reputation:

Bind method to a button in android

I have a button in my layout with the following attribute: android:onClick="nextQ" and in my java code the following method:

public int nextQ()
{
    // do stuff here
    return answer;
}  

Where answer is an integer. Whenever the button is clicked the application closes. Any idea why it breaks?

Upvotes: 4

Views: 4052

Answers (1)

Ted Hopp
Ted Hopp

Reputation: 234797

If you have android:onClick="nextQ", then your context (typically your Activity) must have a method with the signature public void nextQ(View view). See the docs on the onClick attribute.

Upvotes: 8

Related Questions