How do I restrict my EditText input to numerical (possibly decimal and signed) input?

前端 未结 11 1275
旧巷少年郎
旧巷少年郎 2020-12-01 05:20

I have read Android: Limiting EditText to numbers and How do I show the number keyboard on an EditText in android?. Unfortunately, none of them seems to fit my needs.

<
11条回答
  •  庸人自扰
    2020-12-01 05:44

    my solution:`

       public void onTextChanged(CharSequence s, int start, int before, int count) {
       char ch=s.charAt(start + count - 1);
       if (Character.isLetter(ch)) {
           s=s.subSequence(start, count-1);
           edittext.setText(s);
        }
    

提交回复
热议问题