1

I have a fragment that contains EditText and I am trying to setup keyboard event but it doesn't seem to work. The actionId is always 0.

<android.support.v7.widget.AppCompatEditText
    android:id="@+id/input_name"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:hint="@string/hint_name"
    android:inputType="text"
    android:maxLines="1"
    android:imeOptions="actionNext"
    android:digits="abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ"/>

name.setOnEditorActionListener(new TextView.OnEditorActionListener() {
    @Override
    public boolean onEditorAction(TextView v, int actionId, KeyEvent event) {
        boolean handled = false;
        if (actionId == EditorInfo.IME_ACTION_NEXT) {
            save();
            handled = true;
        }
        return handled;
    }
});

I have also tried to set button label using following code but it does not work

name.setImeActionLabel("Next", KeyEvent.KEYCODE_ENTER);
mortalis
  • 2,060
  • 24
  • 34
Coder
  • 3,090
  • 8
  • 49
  • 85

2 Answers2

0

I think you misunderstood with android:digits

Check out android:digits

If set, specifies that this TextView has a numeric input method and that these specific characters are the ones that it will accept. If this is set, numeric is implied to be true. The default is false.

android:digit specifies that this editText will only accept digits. In your case you are defining it with abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ which have no digit, which results in No onEditorAction() tirgger.

Further, actionId will be 0 if you set setImeActionLabel().

Ps,
If you want to filter input of an editText, you should go for InputFilter instead.

Paresh P.
  • 6,677
  • 1
  • 14
  • 26
0

Specifying android:digits to alphabets is only accepting alphabets and any other button click in keyboard is ignored. Thus remove the attribute digits to EditText and add validation to data entered in java file.

sravs
  • 330
  • 2
  • 14