Button.setClickable(false) is not working

前端 未结 11 2150
無奈伤痛
無奈伤痛 2021-01-02 02:19

I have set mButton.setClickable(false); in my code but still this button is invoked by global button.setOnClickListener of my code.

EDIT:

相关标签:
11条回答
  • 2021-01-02 03:06

    Instead of using setClickable(false) use following

    button.setFocusableInTouchMode(false);
    

    I had the same problem in my app where i needed to set my button not to clickable in certain conditions. this worked for me. Hope this helps.

    0 讨论(0)
  • 2021-01-02 03:08

    That seems to be by design. This is from the documentation of the View.setOnClickListener method:

    Register a callback to be invoked when this view is clicked. If this view is not clickable, it becomes clickable.

    0 讨论(0)
  • 2021-01-02 03:11

    I'm not sure if you're still looking for the answer, but for some weird reason

    mBtn.setClickable(true);
    

    stops the view from getting clicked and

    mBtn.setClickable(false);
    

    makes it clickable again.

    0 讨论(0)
  • 2021-01-02 03:13

    You can check like if(!view.isClickable()) return;

    0 讨论(0)
  • 2021-01-02 03:15

    Instead of using setClickable(false) use setEnabled(false)

    0 讨论(0)
提交回复
热议问题