如何在Android中为edittext设置keyListener?

时间:2016-05-03 12:16:07

标签: android-edittext keylistener

我想在EditText中输入一个十六进制数字。如何设置keyListener以限制输入值?

谢谢!

1 个答案:

答案 0 :(得分:1)

在EditText xml中使用android:inputType="number"

您还可以添加文字观察器editText.addTextChangedListener (new MyTextWatcher ());

private class MyTextWatcher implements TextWatcher {

    @Override
    public void beforeTextChanged (CharSequence s, int start, int count, int after) {

    }

    @Override
    public void onTextChanged (CharSequence s, int start, int before, int count) {


    }

    @Override
    public void afterTextChanged (Editable s) {

    }
}