开发者

to check the combination of pressed buttons

I have 4 buttons (a1, a2, b1, b2). They can combinate: a1-b1; a1-b2; a2-b1; a2-b2.It means that "a1" and "a2" cann't be chosen together. So after clicking "a1" I need to block "a2".And depends on what 2 buttons were pressed, it will be differenet actions.I tried something like this

if(a1.isPressed()|| b1.isPressed()){
a2.setClickable(false);
b2.setClickable(false);}

but it didn't work.

Update:

I tried to add boolean variable a1Boolean = false; boolean a2Boolean = false; And after each click `a1.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View v) {
            a1Boolean = true;`

And then to chec开发者_如何学运维k in the method

private boolean geta1_b1() { if (a1Boolean || b1Boolean) { a2.setClickable(false); b2.setClickable(false); } return true; }

but when I call this method before all these clicks, of corse, it didn't work, because I didn't press any buttons yet. Any ideas how to find a right decision?


Use else if statements. That is your best bet for something like this imo.

if(a1.isPressed()){
        a2.setClickable(false);
    }else if(b1.isPressed()){
        b2.setClickable(false)
    }

Make sure that you clear the state when appropriate.


you may try RadioGroup and RadioButton and check which one is selected.


you may invisible button like:

if(a1.isPressed()){ a2.setVisibility(false); }else if(b1.isPressed()){ b2.setVisibility(false) }


Why don't you use RadioGroups?

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜