I have a EditText in which the user should not be able to provide input. So I tried disabling it,by
我有一个EditText,用户不应该在其中提供输入。所以我尝试禁用它
edittext.setEnabled(false);
edittext.setClickable(false);
But still when I press the "next" button in the softKeyboard from some other EditText it directs me to the one which should not be editable and I am able to insert values into it. How to avoid this?
但是当我从其他一些EditText按下softKeyboard中的“next”按钮时,它会将我引导到一个不应该可编辑的按钮,并且我能够将值插入其中。怎么避免这个?
11 个解决方案
#1
37
This works fine; just set focusable property of your edittext to "false" and you are done.
这很好用;只需将edittext的focusable属性设置为“false”即可。
<EditText
android:id="@+id/EditTextInput"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:focusable="false"
android:gravity="right"
android:cursorVisible="true">
</EditText>
#2
29
don't messed up with your self. just simple to work use below one
不要搞砸你的自我。只是简单的工作使用下面一个
First, save the EditText's key listener:
首先,保存EditText的键监听器:
KeyListener mKeyListener = yourTextView.getKeyListener();
yourTextView.setKeyListener(null);
Then if you want to enable editing again, assign the saved listener back:
然后,如果要再次启用编辑,请将已保存的侦听器分配回:
yourTextView.setKeyListener(mKeyListener);
资源
#3
16
yourEditText.setKeyListener(null);
No need to remove focus and setting clickable false.
无需删除焦点并设置可点击的false。
Just remove key listener and you are done.
只需删除关键监听器即可完成。
Also tested with Android 6.0
还使用Android 6.0进行了测试
#4
7
Ok. I did something like this and got the result.
好。我做了这样的事情并得到了结果。
edittext.setEnabled(false);
edittext.setGravity(Gravity.CENTER);
edittext.setClickable(false);
edittext.setFocusable(false);
edittext.setFilters(new InputFilter[] { new textChange() });
edittext.setInputType(0);
class textChange implements InputFilter {
public CharSequence filter(CharSequence source, int start, int end,
Spanned dest, int dstart, int dend) {
return dest.subSequence(dstart, dend);
}
}
#5
4
Try adding
尝试添加
edittext.setFocusable(false); edittest.setFocusableInTouchMode(false);
edittext.setFocusable(假); edittest.setFocusableInTouchMode(假);
#6
3
android:focusable="false"
android:longClickable="false"
Adding these two fields to your EditText will disables the focus and also disables the copy pasting data into your EditText field.
将这两个字段添加到EditText将禁用焦点,并禁用将数据粘贴到EditText字段中的副本。
#7
1
Take a look at this
看看这个
editText.setEnabled(false);
and editText.setFocusable(false);
will achieve.
editText.setEnabled(假);和editText.setFocusable(false);会实现的。
#8
0
In your EditText Xml Code . Paste below line.
在您的EditText Xml代码中。粘贴到下面的行。
android:focusable="false"
#9
0
android:focusable="false"
worked for me.
为我工作。
#10
0
Use imeOptions attribute to change that button in softKeyboard to done
使用imeOptions属性将softKeyboard中的该按钮更改为完成
android:imeOptions="actionDone"
机器人:imeOptions = “actionDone”
add it to EditText just previous to the one you want to disable.
将它添加到您要禁用的之前的EditText。
#11
0
It might be somebody helpful. I've found one implementation:
这可能是有帮助的。我发现了一个实现:
@Override
public boolean onTouch(View v, MotionEvent event) {
//for edit text
return locked;
}
where locked
is locked state.
锁定状态为锁定状态。
of course, i have to use editText.setOnTouchListener(<listener>);
当然,我必须使用editText.setOnTouchListener(
#1
37
This works fine; just set focusable property of your edittext to "false" and you are done.
这很好用;只需将edittext的focusable属性设置为“false”即可。
<EditText
android:id="@+id/EditTextInput"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:focusable="false"
android:gravity="right"
android:cursorVisible="true">
</EditText>
#2
29
don't messed up with your self. just simple to work use below one
不要搞砸你的自我。只是简单的工作使用下面一个
First, save the EditText's key listener:
首先,保存EditText的键监听器:
KeyListener mKeyListener = yourTextView.getKeyListener();
yourTextView.setKeyListener(null);
Then if you want to enable editing again, assign the saved listener back:
然后,如果要再次启用编辑,请将已保存的侦听器分配回:
yourTextView.setKeyListener(mKeyListener);
资源
#3
16
yourEditText.setKeyListener(null);
No need to remove focus and setting clickable false.
无需删除焦点并设置可点击的false。
Just remove key listener and you are done.
只需删除关键监听器即可完成。
Also tested with Android 6.0
还使用Android 6.0进行了测试
#4
7
Ok. I did something like this and got the result.
好。我做了这样的事情并得到了结果。
edittext.setEnabled(false);
edittext.setGravity(Gravity.CENTER);
edittext.setClickable(false);
edittext.setFocusable(false);
edittext.setFilters(new InputFilter[] { new textChange() });
edittext.setInputType(0);
class textChange implements InputFilter {
public CharSequence filter(CharSequence source, int start, int end,
Spanned dest, int dstart, int dend) {
return dest.subSequence(dstart, dend);
}
}
#5
4
Try adding
尝试添加
edittext.setFocusable(false); edittest.setFocusableInTouchMode(false);
edittext.setFocusable(假); edittest.setFocusableInTouchMode(假);
#6
3
android:focusable="false"
android:longClickable="false"
Adding these two fields to your EditText will disables the focus and also disables the copy pasting data into your EditText field.
将这两个字段添加到EditText将禁用焦点,并禁用将数据粘贴到EditText字段中的副本。
#7
1
Take a look at this
看看这个
editText.setEnabled(false);
and editText.setFocusable(false);
will achieve.
editText.setEnabled(假);和editText.setFocusable(false);会实现的。
#8
0
In your EditText Xml Code . Paste below line.
在您的EditText Xml代码中。粘贴到下面的行。
android:focusable="false"
#9
0
android:focusable="false"
worked for me.
为我工作。
#10
0
Use imeOptions attribute to change that button in softKeyboard to done
使用imeOptions属性将softKeyboard中的该按钮更改为完成
android:imeOptions="actionDone"
机器人:imeOptions = “actionDone”
add it to EditText just previous to the one you want to disable.
将它添加到您要禁用的之前的EditText。
#11
0
It might be somebody helpful. I've found one implementation:
这可能是有帮助的。我发现了一个实现:
@Override
public boolean onTouch(View v, MotionEvent event) {
//for edit text
return locked;
}
where locked
is locked state.
锁定状态为锁定状态。
of course, i have to use editText.setOnTouchListener(<listener>);
当然,我必须使用editText.setOnTouchListener(