How do you check whether a button is enabled or not in Android?
Asked Answered
S

2

6

In Android I can set a button to be enabled or disabled by doing the following:

button.setEnabled(true); or button.setEnabled(false);

How do I check whether the button enabled state is true or false?

Selfsupport answered 27/5, 2011 at 4:0 Comment(0)
D
21

Reading the manual every now and then doesn't hurt:

http://developer.android.com/reference/android/view/View.html#isEnabled%28%29

Example:

ImageButton myButton = (ImageButton) findViewById(R.id.epic_button);

if (myButton.isEnabled()){
    //then the button is enabled.
}
Debera answered 27/5, 2011 at 4:8 Comment(3)
it doesn't hurt for sure. I was looking for getEnable() and didn't think about isEnable()Selfsupport
:) As a general rule, for toggling properties out there, you'll have a "setProperty" to set it, and a "isProperty" to check what's its value ^_^Debera
How can one be notified when that value changes? For instance, I need to let the children of a ViewGroup of the parents' isEnabled state.Calvinism
C
10
button.isEnabled() 

returns true if enabled

Cursive answered 27/5, 2011 at 4:12 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.