Search code examples
androidandroid-edittext

How to i can disable some button in "edittext" keyboard


I want to disable some buttons into the soft keyboard.

For example, I want to disable the 0 button then my edittext is empty.

edt.addTextChangedListener(new TextWatcher() {

@Override
public void onTextChanged(CharSequence cs, int arg1, int arg2, int arg3) {

}

@Override
public void beforeTextChanged(CharSequence s, int arg1, int arg2, int arg3){

}

@Override
public void afterTextChanged(Editable arg0) {

}

});

Solution

  • You can't, sorry. After all, the input method editor may not have "keys" in the first place.

    Specifically I want user can't input a ( , ) character when virtual keyboard is showed up when user focus on a standard android EditText widget.

    Then you will have to block the input at the EditText, by means of an InputFilter, as is described here:

    InputFilter filter = new InputFilter() {
        public CharSequence filter(CharSequence source, int start, int end,
                Spanned dest, int dstart, int dend) {
            for (int i = start; i < end; i++) {
                if (!Character.isLetterOrDigit(source.charAt(i))) {
                    return "";
                }
            }
            return null;
        }
    };
    edit.setFilters(new InputFilter[] { filter });