我正在尝试实现一个EditText
,限制输入为大写字符[A-Z0-9],包括数字。
我从一篇文章中开始使用了InputFilter方法,但在三星Galaxy Tab 2上出现了问题,在模拟器或Nexus 4上没有问题。
问题如下:
- 当我输入"A"时,文本显示为"A",很好
- 现在当我输入"B"时,文本应该是"AB",但它给我"AAB",看起来非常奇怪。
简而言之,它重复了字符。
以下是我正在使用的代码:
public class DemoFilter implements InputFilter {
public CharSequence filter(CharSequence source, int start, int end, Spanned dest, int dstart,
int dend) {
if (source.equals("")) { // for backspace
return source;
}
if (source.toString().matches("[a-zA-Z0-9 ]*")) // put your constraints
// here
{
return source.toString().toUpperCase();
}
return "";
}
}
XML文件代码:
<EditText
android:id="@+id/et_licence_plate_1"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="3"
android:hint="0"
android:imeOptions="actionNext"
android:inputType="textNoSuggestions"
android:maxLength="3"
android:singleLine="true"
android:textSize="18px" >
</EditText>
我完全被这个问题卡住了,所以任何帮助都将不胜感激。