开发者

Make a Layout inactive in android

开发者 https://www.devze.com 2023-03-05 21:16 出处:网络
I have a RelativeLayout and in this RelativeLayout there are 4 Buttons. Outside this RelativeLayout there is CheckBox.The whole View is in a RelativeLayout.

I have a RelativeLayout and in this RelativeLayout there are 4 Buttons. Outside this RelativeLayout there is CheckBox.The whole View is in a RelativeLayout.

I want to make the 4 Buttons 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.

0

精彩评论

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