Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Android: disabled View gets focus

I don't know exactly how to search about this topic, so I hope there isn't the same question here around.

In a "menu" of my Activity, I have two RadioButtons with EditText's, the user should choose one of the two options and then enter some values in the EditText. The first RadioButton, however, has an additional Option which is choosable via a CheckBox, so that if the user checks that CheckBox, a further EditText is enabled. The EditText's are dis- and enabled via onCheckedChangeListener on both RadioButtons and the CheckBox like this

radio1.setOnCheckedChangeListener(new OnCheckedChangeListener() {
            public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
                if(isChecked){
                    if(radio2.isChecked()){
                        radio2.setChecked(false);
                    }
                    edit1.setEnabled(true);
                    check1.setEnabled(true);
                }else{
                    check1.setEnabled(false);
                    check1.setChecked(false);
                }   
            }
        });

Now the problem is, when I choose option one, and enter a value in the first EditText, and the second one is still disabled, I can press the "forward-button" (I really don't know how it's called, see the image below) and the disabled EditText gets focused.

enter image description here

And here's the EditText that shouldn't be focused

enter image description here

Shouldn't it be that a disabled View could not get foucsed? It is absolutely illogical that this is even possible. Is there a way to set this generally or have I add setFocusable(boolean) every time I change the status?

like image 944
Valentino Ru Avatar asked Sep 22 '26 04:09

Valentino Ru


1 Answers

The editTexts even though setEnabled as false can still receive focus. To disable the focus apply editText.setFocusable(false). On applying this on clicking the imeOption on the softkeyboard will then hide the softkeyboard if no other editable elements are present.

like image 140
Reuben Pinto Avatar answered Sep 24 '26 19:09

Reuben Pinto



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!