代码之家  ›  专栏  ›  技术社区  ›  Praveen

Android中的EditText?

  •  3
  • Praveen  · 技术社区  · 15 年前

    EditText 在运行时。

    例如:

    如果我把我的 android:inputType="numberDecimal"

    2 回复  |  直到 15 年前
        1
  •  6
  •   Scoobler    15 年前

    看看下面的帖子,也许对你有帮助:

    Preventing input

    EditText txtInput = (EditText) findViewById(R.id.txtInput);
    txtInput.addTextChangedListener(new TextWatcher() 
    {
        public void afterTextChanged(Editable edt) 
        {
            String temp = edt.toString();
            int posDot = temp.indexOf(".");
            if (posDot <= 0) return;
            if (temp.length() - posDot - 1 > 2)
            {
                edt.delete(posDot + 3, posDot + 4);
            }
        }
    
        public void beforeTextChanged(CharSequence arg0, int arg1, int arg2, int arg3) {}
    
        public void onTextChanged(CharSequence arg0, int arg1, int arg2, int arg3) {}
    });
    
        2
  •  2
  •   Macarse    15 年前

    EditText 使用 TextWatcher .