Button setonclicklistener error

前端 未结 6 1958
感情败类
感情败类 2020-12-31 23:43

I am having a problem right now with setOnClickListener.

When i put this following line:

button.setOnClickListener(this);
6条回答
  •  感动是毒
    2021-01-01 00:24

    Although it's been a long time, thought it might help others who have this problem, it took me many trials to get it right. But i think what finally solved my problem was setting the clickable attribute of a button in the layout's xml to true.
    Code sample:

    
    

    Further, if you would've looked at the DDMS perspective, you would've seen that the cause of the error was NullPointerException, which ofcourse was showing because clickable wasn't set. Correct me if i am wrong.

提交回复
热议问题