Question

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?

Was it helpful?

Solution

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.

OTHER TIPS

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

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top