Genderic EditText keyboard sometimes doesn't allow numbers

The following code creates an EditText (target version 23). I have been working on this for about 8 hours and got some suggestions, but I don't think anyone has ever seen this before, so I stay stuck.

  • Click on the box.
  • The soft A / N keyboard opens.
  • Press the 123 button? Button at the bottom left. The numeric keypad opens.
  • Press any number. Nothing has happened.
  • Long press 5, "5/8" is added to the text box.
  • Press any special character, for example @. He can add to the box.
  • Clear the field. Enter β€œfor”, press 123 ?, Now it will accept the numbers.
  • Clear the field. Enter β€œfor?”, Press 123 ?, it will not accept numbers.

I added TextWatcher. If the numbers did not fit, TextWatcher did not see them either.

EditText bottomT = new EditText(model); bottomT.setTextSize(14); bottomT.setHint("ZIP"); bottomT.setHintTextColor(Color.BLACK); bottomT.setBackgroundColor(Color.WHITE); bottomT.setTextColor(Color.BLACK); // bottomT.setInputType(InputType.TYPE_CLASS_NUMBER) Didn't make any difference. // bottomT.setRawInputType(InputType.TYPE_CLASS_NUMBER) Didn't make any difference. // bottomT.setText("", TextView.BufferType.EDITABLE); DIdn't make a difference bottomT.setText(""); 
+2
android android-edittext
Nov 28 '15 at 4:35
source share
3 answers

EditText fails because in my user group ViewGroup I had

  protected void onLayout(boolean changed, int l, int t, int r, int b) { .... child.layout(child.getLeft(), child.getTop(), child.getLeft() + child.getMeasuredWidth(), child.getTop() + child.getMeasuredHeight()); child.setRight(somevalue); // CAUSES EDITTEXT PROBLEMS child.setBottom(somevalue); // CAUSES EDITTEXT PROBLEMS 

Now it’s clear that I cannot setRight () and setBottom (), but it’s also clear that EditText should not be weird.

Ignore the backspace key.

Accidentally ignore the number keys, but accept the decimal point.

Ignore newLine (Enter) key

Which keys are ignored or not depends on the device. Samsung Tab 4 or the Nexus 5 API 23 X86 emulator are good places to see this.

+1
Dec 12 '15 at 3:45
source share

You must add this line to your Java code.

 bottomT.setInputType(EditorInfo.TYPE_CLASS_NUMBER); 
0
Nov 28 '15 at 8:45
source share

Try this line of code.

 bottomT.setInputType(InputType.TYPE_CLASS_NUMBER |InputType.TYPE_NUMBER_FLAG_DECIMAL); 
0
Nov 28 '15 at 18:08
source share



All Articles