EditText TYPE_CLASS_NUMBER不接受输入

时间:2015-11-26 06:05:59

标签: android android-edittext

下面的代码生成EditText,但在仅数字软键盘出现后,无法识别输入。如果我将setInputType更改为TYPE_CLASS_TEXT,则效果恰到好处。我已经阅读并重读了所有关于此的帖子,但我没有看到任何拒绝接受输入的内容。

// And a zip code
        zip = Util.buildOneLine("ZIP");
        zip.setInputType(InputType.TYPE_CLASS_NUMBER);
        zip.addTextChangedListener(new TextWatcher()
        {
            @Override
            public void onTextChanged(CharSequence s, int start, int before, int count)
            {
                Log.w(TAG, "jkljl");
            }

            @Override
            public void beforeTextChanged(CharSequence s, int start, int count,
                                          int after)
            {
                Log.w(TAG, "jkljl");
            }

            @Override
            public void afterTextChanged(Editable s)
            {
                Log.w(TAG, "jkljl");
            }
        });

 public static EditText buildOneLine(String heading)
{

    EditText bottomT = new EditText(this);
    bottomT.setTextSize(TypedValue.COMPLEX_UNIT_PX, adjustedFont(14));
    bottomT.setHint(heading);
    temp.setSingleLine(true);
    bottomT.setGravity(Gravity.CENTER_VERTICAL);
    setLayout(bottomT);


    return temp;
}

2 个答案:

答案 0 :(得分:0)

试试这个:

zip.setRawInputType(InputType.TYPE_CLASS_NUMBER |InputType.TYPE_NUMBER_FLAG_DECIMAL);

答案 1 :(得分:0)

EditText行为不端,因为在我的自定义ViewGroup中有

 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

现在很清楚我不能设置setRight()和setBottom(),但是也很清楚EditText不应该变得怪异。

忽略退格键。

随机忽略数字键,但接受小数点。

忽略newLine(Enter)键

哪些键被忽略或取消,取决于设备。三星Tab 4或Nexus 5 API 23 X86仿真器是看到这个的好地方。

相关问题