开发者

Bind method to a button in android

开发者 https://www.devze.com 2023-03-06 06:15 出处:网络
I have a button in my layout with the following attribute: android:onClick=\"nextQ\" and in my java code the following method:

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?


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.

0

精彩评论

暂无评论...
验证码 换一张
取 消