SetFocus (false) ; 不能设置为 true. :/

一个非常奇怪的情况,我得到了这个代码,它应该使一个 EditText 文件不可编辑,如果 SpnSelected.equals (“ Service”)和可编辑,如果它的其他东西。

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);
}

它确实使得它不能编辑,但是它不能使用 etAdd.setFocus 返回编辑(true) ;

有什么办法吗? 谢谢! :)

24806 次浏览

You have to set the EditText to

etAdd.setEnabled(false);

Try

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

instead of just

etAdd.setFocusable(true);

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

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

my code work well using editText.requestFocus();