Android: EditText cannot gain focus after being re-enabled-ThrowExceptions

Exception or error:

I have a TabHost with three tabs. The first tab’s content is the Intent of a custom activity who’s contentview is a relative layout containing two EditTexts and two CheckBoxes (and a button).

Each checkbox, when checked, enables/disables one EditText and the other checkbox. and I went about that like this:

chkPolaziste.setOnCheckedChangeListener(new OnCheckedChangeListener()
    {
        public void onCheckedChanged(CompoundButton buttonView, boolean isChecked)
        {
            if ( isChecked )
            {
                entryPolaziste.setFocusable(false);
                entryPolaziste.setEnabled(false);
                chkOdrediste.setFocusable(false);
                chkOdrediste.setEnabled(false);
            }
            else
            {
                entryPolaziste.setEnabled(true);
                entryPolaziste.setFocusable(true);
                chkOdrediste.setEnabled(true);
                chkOdrediste.setFocusable(true);
            }
        }
    });

And that works. When one checkbox is checked, it disables the other checkbox and his EditText, and when I uncheck it, EditText and the other checkbox are enabled. But, after it’s enabled, I can’t type anything into the EditText. It just flicks for a moment when I
click on it, and switches focus to another view. It looks to me as though the control is not fully enabled.

I’ve also tried to force the focus on the re-enabled EditText with requestFocus(), and tried to setFocusableInTouchMode(), but neither had worked.

I don’t have an android device, so I only test this in the emulator (Min SDK is 1.6).

How to solve:

Workaround:

Use setFocusableInTouchMode and setFocusable, both of them.

Leave a Reply

Your email address will not be published. Required fields are marked *