EditText.setFocusable(false); can't be set to true. :/

JavaAndroid

Java Problem Overview


A very strange situation, I've got this code that is supposed to make an EditText filed uneditable if SpnSelected.equals("Service") and editable again, if its something else.

final EditText etAdd = (EditText)dialogAddTextView.findViewById(R.id.etSymb);

    if ( SpnSelected.equals("Service") )
    {
    	etAdd.setFocusable(false);
    	TextView tvInfo = (TextView)dialogAddTextView.findViewById(R.id.tvAddTextInfo);
    }
    else
    {
    	etAdd.setFocusable(true);
    	TextView tvInfo = (TextView)dialogAddTextView.findViewById(R.id.tvAddTextInfo);
    } 

It does make it uneditable ok, but it doesn't bring the ability to edit back with etAdd.setFocusable(true);

Any ideas what to do about it? Thanks! :)

Java Solutions


Solution 1 - Java

Try

etAdd.setFocusableInTouchMode(true);
etAdd.setFocusable(true);

instead of just

etAdd.setFocusable(true);

Solution 2 - Java

I use below code focus and click remove and add:

Remove: secondFirstHalfEditText.setClickable(false); secondFirstHalfEditText.setFocusable(false);

Add :

editText.setClickable(true);
editText.setFocusableInTouchMode(true);
editText.setFocusable(true);

Must use this For active Edittext >>

editText.setFocusableInTouchMode(true);

Its working for me perfecly

Solution 3 - Java

This solution has worked for me :

 EditText test3 = (EditText) findViewById(R.id.edittext);
 CheckBox check1= (CheckBox) findViewById(R.id.checkBox1);
 test3.setClickable(false);
 test3.setEnabled(false);
 test3.setFocusable(false);
 check1.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
    public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
      if(check1.isChecked()){
         test3.setText("");
         test3.setClickable(false);
         test3.setEnabled(false);
         test3.setFocusable(false);
      } else {
         test3.setClickable(true);
         test3.setEnabled(true);
         test3.setFocusable(true);
         test3.setFocusableInTouchMode(true);
      }
    }
 });

After i check the checkbox the edittext is disabled.

i hope it will help someone :)

Solution 4 - Java

my code work well using editText.requestFocus();

Solution 5 - Java

You have to set the EditText to

etAdd.setEnabled(false);

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionRogerView Question on Stackoverflow
Solution 1 - JavaBala RView Answer on Stackoverflow
Solution 2 - JavaShohel RanaView Answer on Stackoverflow
Solution 3 - JavaYohanfouView Answer on Stackoverflow
Solution 4 - JavaVanya RachelView Answer on Stackoverflow
Solution 5 - JavaNewProggieView Answer on Stackoverflow