Android学习笔记——设置EditText只输入数字、字母
16lz
2021-01-26
如何设置EditText,使得只能输入数字或者某些字母呢?
一、设置EditText,只输入数字:
方法1:直接生成DigitsKeyListener对象就可以了。
et.setKeyListener(new DigitsKeyKistener(false,true));
方法2:在EditText中设置属性,android:numeric="integer"即只能输入整数,
方法3:新建一个char[],在里面添加允许输入的字符。如下
et.setKeyListener(new NumberKeyListener(){
protected char[] getAcceptedChars(){
char[] numberChars = {'1','2',.....}};
return numberChars;
});
二、设置EditText只能输入某些字母,如下面设置edtitext只能输入A—N,a—n这些字母。方法如下:
et.setKeyListener(new NumberKeyListener()
{
public int getInputType(){
return 0;
}
protected char[] getAcceptedChars(){
char[] myChar = {'a','b',......};
return myChar;
}
});
http://chuangwangcc.blog.163.com/blog/static/1323036612010627113855576/更多相关文章
- android 控制软键盘显示和隐藏
- Android(安卓)Permission访问权限许可
- android 签名发布
- ubuntu genymotion 启动adb 被占用5037端口
- 暂时只会这种导航,实时显示自己的位置,,求其他更好的方法,或api
- [置顶] android:autoLink
- android中的LayoutInflater简单运用
- android47
- 【BottomBar】Android底部导航栏V2.0