Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Android: EditText cannot gain focus after being re-enabled

Tags:

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).

like image 916
dr.lijenjin Avatar asked Jun 25 '10 12:06

dr.lijenjin


1 Answers

Workaround:

Use setFocusableInTouchMode and setFocusable, both of them.

like image 120
arpia49 Avatar answered Jan 02 '23 23:01

arpia49