又怎么限制只能输入4位数字?

解决方案 »

  1.   

    我认为不一定要在输入上限制呢?if如果获取后大于999小于1就成功,不行setText=“”。个人意见勿喷
      

  2.   

    api文档android:digits   设置允许输入哪些字符。如“1234567890.+-*/%\n()”
    你懂的
      

  3.   

    api文档android:maxLength   限制输入字符数。如设置为4,那么仅可以输入4个汉字/数字/英文字母。你懂的
      

  4.   

    看看api文档,应该可以达到要求
      

  5.   

    给editText先设置在xml中设置inputType为数字,然后给其添加TextWatcher,监听文本的变化,取到文本并做相应判断
      

  6.   

    android:maxLength 
    Since: API Level Set an input filter to constrain the text length to the specified number. Must be an integer value, such as "100". This may also be a reference to a resource (in the form "@[package:]type:name") or theme attribute (in the form "?[package:][type:]name") containing a value of this type. This corresponds to the global attribute resource symbol maxLength.
      

  7.   

    监听判断一下,如果改变后不符合要求则提示,或则不想让用户输入,则监听到不符合的数字时setText(getText().replace("x"));
    嗯嗯,俺就想到这样子的方法
      

  8.   

    设置android:inputType为number,然后设置android:maxLength为4
      

  9.   

    3L真相,可以通过设置EditText属性直接解决
    不需要通过在java代码内面if判断什么的
      

  10.   

    android:maxLength="4"
    android:inputType="number"属性里边这么写,OK了