EditText.setFocusable(false);不能设置为 true。:/

2022-08-31 13:14:36

一个非常奇怪的情况,我有这个代码,它应该使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.setFocusable(true)进行编辑的能力;

任何想法该怎么办?谢谢!:)


答案 1

尝试

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

而不仅仅是

etAdd.setFocusable(true);

答案 2

我使用以下代码焦点,然后单击删除并添加:

删除:secondFirstHalfEditText.setClickable(false); secondFirstHalfEditText.setFocusable(false);

加:

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

必须使用此选项 对于活动编辑文本>>

editText.setFocusableInTouchMode(true);

它为我工作得很周到


推荐