如何设置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/

更多相关文章

  1. android 控制软键盘显示和隐藏
  2. Android(安卓)Permission访问权限许可
  3. android 签名发布
  4. ubuntu genymotion 启动adb 被占用5037端口
  5. 暂时只会这种导航,实时显示自己的位置,,求其他更好的方法,或api
  6. [置顶] android:autoLink
  7. android中的LayoutInflater简单运用
  8. android47
  9. 【BottomBar】Android底部导航栏V2.0

随机推荐

  1. Android中Shape Drawable在xml中的使用
  2. android 事件模型
  3. ios 开发之基础控件
  4. Android(安卓)开发环境安装
  5. stagefright概述
  6. Android系统启动流程 -- linux kernel
  7. 【Android(安卓)声音处理】MediaPlayer和
  8. Android(安卓)View 事件分发机制详解
  9. android相对布局--计算器的例子
  10. Android(安卓)学习之- 单选按钮、复选框