2

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

  1. Click on the field.
  2. The A/N soft keyboard opens up.
  3. Click the 123? button at bottom left. The numeric soft keyboard opens up.
  4. Press any digit. Nothing happens.
  5. Long press 5, "5/8" gets added into the text field.
  6. Press any special character, such as @. It might add to the field.
  7. Clear the field. Type "for", press 123?, now it will take digits.
  8. Clear the field. Type "for?", press 123?, it will not take digits.

I added a TextWatcher. If the digits didn't post, the TextWatcher didn't 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(""); 
Bob Lissner
  • 255
  • 4
  • 17

3 Answers3

1

EditText is misbehaving because in my custom 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

It’s clear now that I can't setRight() and setBottom(), but it’s also clear that EditText should not get weird.

Ignore the backspace key.

Randomly ignore numeric keys, but accept the decimal point.

Ignore the 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.

Bob Lissner
  • 255
  • 4
  • 17
0

You have to add this line in your java code.

bottomT.setInputType(EditorInfo.TYPE_CLASS_NUMBER);
Avijit Karmakar
  • 8,890
  • 6
  • 44
  • 59
  • EditorInfo.TYPE_CLASS_NUMBER and InputType.TYPE_CLASS_NUMBER produce identical results: The numeric keypad comes up and no typing is accepted. – Bob Lissner Nov 28 '15 at 17:29
  • But it's not working on my system. It will accept the decimal point, but no numbers before or after. There is something in EditText that is deciding whether or not to display numbers 0 - 9. It seems almost random. – Bob Lissner Nov 29 '15 at 01:46
0

Try this line of code .

bottomT.setInputType(InputType.TYPE_CLASS_NUMBER |InputType.TYPE_NUMBER_FLAG_DECIMAL);
Arslan Ashraf
  • 867
  • 7
  • 12