我用上面的语句来限制我的EditText部分字符,这是很好的工作在我Motorolo(安卓2.3),但它显示的数字键盘在谷歌Nexus。
请提供了解决方案。
解决方案第一次尝试添加安卓位数=ABCDE ..... 012345789
属性。虽然安卓位数
指定它是一个数字字段,但它接受信件以及。
或
试试这个code ..
T1 =(EditText上)findViewById(R.id.text);
t1.setFilters(新输入过滤器[] {
新的输入过滤器(){
公共CharSequence的过滤器(SRC的CharSequence,诠释开始,
INT端,跨区DST,INT DSTART,诠释DEND){
如果(src.equals()){//退格键
返回SRC;
}
如果(src.toString()。匹配([A-ZA-Z0-9] *))//把你限制在这里
{
返回SRC;
}
返回 ;
}
}
});
或 看到此链接
searchEdit.setKeyListener(DigitsKeyListener.getInstance("abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789 &"));
I used the above statement for restricting my edittext to some characters,it is working well in my Motorolo(Android 2.3),but it is showing numeric keyboard in Google nexus.
Please provide the solution.
解决方案First try with adding the android:digits="abcde.....012345789"
attribute.Although the android:digits
specify that it is a numeric field but it accept letters as well.
Or,
try this code..
t1 = (EditText)findViewById(R.id.text);
t1.setFilters(new InputFilter[] {
new InputFilter() {
public CharSequence filter(CharSequence src, int start,
int end, Spanned dst, int dstart, int dend) {
if(src.equals("")){ // for backspace
return src;
}
if(src.toString().matches("[a-zA-Z0-9 ]*")) //put your constraints here
{
return src;
}
return "";
}
}
});
Or, see an useful example from This Link