Bind method to 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 the answer is an integer. Whenever a button is pressed, the application closes. Any idea why it breaks?

+3
source share
1 answer

If you have android:onClick="nextQ", then your context (usually your activity) should have a method with a signature public void nextQ(View view). See documents in the onClick attribute .

+7
source

All Articles