【问题标题】:Android: Restrict editText entry after certain lengthAndroid:在一定长度后限制editText条目
【发布时间】:2016-08-26 10:14:06
【问题描述】:

您好,我在编辑文本时使用了文本观察器 我想限制一定长度后的数字

suppose i want restrict length for  3
It should not allow 1234
but it should allow 123.(except dot(.) it should not allow any other character)

如何使用 TextWatcher。

还尝试限制除点以外的所有关键条目但不起作用

insideEdit.setOnKeyListener(new OnKeyListener() {

            @Override
            public boolean onKey(View v, int keyCode, KeyEvent event) {
                  if (keyCode == 46) // dot key code is 46
                    {

                        return false;
                    }else {

                        return true;
                    }

            }
        });

【问题讨论】:

    标签: android-edittext android-textwatcher


    【解决方案1】:

    使用

    android:maxLength="4"
    

    <EditText标签内

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2019-09-19
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多