Make a Layout inactive in android
I have a RelativeLayout
and in this RelativeLayout
there are 4 Button
s. Outside this RelativeLayout
there is CheckBox
.The whole View
is in a RelativeLayout
.
I want to make the 4 Button
s to inactive (which are present in the RelativeLayout
) by selecting on CheckBox
and I want开发者_如何学编程 to make all the buttons active when I again select the CheckBox
. so what to do ?
I have also tried relativeLayout.setClickable(false);
but it is not working.
final int[] BUTTON_IDS = { R.id.button1, R.id.button2, };
checkBox.setOnCheckedChangeListener(new OnCheckedChangeListener() {
@Override
public void onCheckedChanged(CompoundButton buttonView,
boolean isChecked) {
for (int btnId = 0; btnId < BUTTON_IDS.length; btnId++) {
Button btn = (Button) findViewById(btnId);
btn.setEnabled(isChecked);
}
}
});
UTDATE
Try this:
<yourRelativeLayout>.setEnabled(false);
or you can change state of all your buttons to disabled.
精彩评论