EditText.setFocusable (false); cannot be set to true.:/

A very strange situation, I have this code that should make EditText registered uneditable if SpnSelected.equals ("Service") and edited again if 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 makes it uneditable ok, but it does not allow editing back using etAdd.setFocusable (true);

Any ideas what to do about it? Thank you :)

+46
java android
Sep 13 '11 at 20:12
source share
4 answers

Try

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

instead

 etAdd.setFocusable(true); 
+153
Sep 13 '11 at 20:25
source share

This solution 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 checked, edittext is disabled.

I hope this helps someone :)

+2
Jun 25 2018-12-12T00:
source share

I use the code focus below and click "Delete" and add:

Remove: secondFirstHalfEditText.setClickable(false); secondFirstHalfEditText.setFocusable(false); 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); 

His work is perfect for me

0
Nov 30 '17 at 6:19 06:19
source share

You must set EditText to

 etAdd.setEnabled(false); 
-3
Sep 13 2018-11-21T00:
source share



All Articles