1

I have an android ButtonView,

I set it to be unclickable:

 mDoneBtn.setClickable(false);

later I set an onClickListener to it

mDoneBtn.setOnClickListener(new View.OnClickListener() {

does the latter make the button to be clickable again?

1
  • @User22791 you are wrong.
    – kai
    Apr 24, 2014 at 11:49

2 Answers 2

5

First you write:

mDoneBtn.setClickable(false);

Then you set onClick:

mDoneBtn.setOnClickListener(new View.OnClickListener() {...}

The button will trigger onClick event.

But if you set as:

mDoneBtn.setEnabled(false);

and then set your onClick, the onClick event will not be triggered.

Requested Edit:

setClickable automatically becomes true if onClickListenner is implemented. if you do setEnabled(false), until it is set to true, it will not be clickable even if you implement onClickListenner.

6
  • you wrote the same order twice
    – Elad Benda
    Apr 24, 2014 at 13:26
  • they are different. up: setClickable down: setEnabled
    – canova
    Apr 24, 2014 at 13:36
  • what is the difference btw?
    – Elad Benda
    Apr 25, 2014 at 10:41
  • 1
    setClickable automatically becomes true if onClickListenner is implemented. if you do setEnabled(false), until it is set to true, it will not be clickable even if you implement onClickListenner.
    – canova
    Apr 25, 2014 at 10:43
  • can you add this to you answer? it's all true to API 8 ?
    – Elad Benda
    Apr 25, 2014 at 10:54
4

From View source:

public void setOnClickListener(OnClickListener l) {
        if (!isClickable()) {
            setClickable(true);
        }
        getListenerInfo().mOnClickListener = l;
}

I guess you can figure out the answer.

EDIT: valid for API level 19

1
  • it happens for API 8 as well. If i change the order the button isn't clickable.
    – Elad Benda
    Apr 24, 2014 at 13:26

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.