0

I've searched and searched and I can't seem to catch a press on the "arrow" key on the android EditText keyboard. For me, it's the button right underneath the backspace that looks like an arrow.

I have tried using:

            @Override
        public boolean onEditorAction(TextView v, int actionId, KeyEvent event) {


            System.out.println(actionId);

            if (event.getAction() != KeyEvent.ACTION_DOWN) {
                System.out.println("event.getAction() != KeyEvent.ACTION_DOWN");
                return false;
            }

            if (actionId == EditorInfo.IME_ACTION_NEXT) {
                System.out.println("keyCode == KeyEvent.FLAG_EDITOR_ACTION");

                trialNumber++;
                trialNumberTextView.setText("Trial" + Integer.toString(trialNumber));

                return true;
            }

            System.out.println("false");

            return false;
        }

    });

EditText:

<EditText
    android:id="@+id/sack_edit_text"
    android:textSize="30dp"
    android:textAlignment="center"
    android:hint="@string/trial_hint"
    android:layout_centerInParent="true"
    android:layout_width="150dp"
    android:layout_height="wrap_content"
    android:inputType="numberDecimal"
    android:digits="0123456789."
    android:maxLength="2"/>

But nothing is printed out at all when I click the arrow button. This works for the digits on the keyboard however. I have tried changing the arrow button to a Done button in the EditText xml, but that doesn't work either. Does anyone know why this is?

Brejuro
  • 3,421
  • 8
  • 34
  • 61

2 Answers2

1

In your layout, just set the XML attributes android:imeOptions="actionNext". You need to give your edittext single line true in xml.

android:singleLine="true"

and catch the next action on keyboard like:

 some_edittext.setOnEditorActionListener(new OnEditorActionListener() {
        public boolean onEditorAction(TextView v, int actionId, KeyEvent event) {
            if (actionId == EditorInfo.IME_ACTION_NEXT) {
                some_button.performClick();
                return true;
            }
            return false;
        }
    });

Also check This So post for a detailed description about softkeyboard actions.

Community
  • 1
  • 1
Anirudh Sharma
  • 7,968
  • 13
  • 40
  • 42
0

Add android:imeOptions="actionNext" to your EditText in XML.

Next, set OnEditorActionListener on youe edittext like this,

etSack.setOnEditorActionListener(new TextView.OnEditorActionListener() {

        @Override
        public boolean onEditorAction(TextView v, int actionId, KeyEvent event) {

            ...your code...

            if (actionId == EditorInfo.IME_ACTION_NEXT) {
              System.out.println("keyCode == KeyEvent.FLAG_EDITOR_ACTION");

              trialNumber++; 
              trialNumberTextView.setText("Trial" +        Integer.toString(trialNumber));

              return true; 
            } 

            System.out.println("false");
            return false;
        }

    });
Shubham A.
  • 2,446
  • 4
  • 36
  • 68