开发者

Android + setOnClickListener sets setClickable to true by default?

I have a ButtonView in an xml layout and set the focusable/clickable attributes to false. I'm attempting to prevent click events on the ButtonView until a flag is set to true. Anyway, this works fine until I write the setOnClickListner code on the ButtonView. It seems to automatically set setClickable() to true. Is there a way to prevent this, or is this the default behavior? I figured I could开发者_开发技巧 set the listener at any time, and ignore events until I set setClickable() on the Button. Thanks, any help is appreciated!


http://developer.android.com/reference/android/view/View.html#setOnClickListener(android.view.View.OnClickListener)

This behavior is documented.

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


In addition to what Snicolas said.

You can disable the button for that purpose. Then no callback on the setOCL() will be triggered when your button is clicked.


since you already have the option of setting setClickable() at your disposal.

i assume you are wondering about any best practice.

just curious, will not making the button disabled be more intuitive to the user about the situation.

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜