0

I have a problem with the Enter key in android, I have an edittext where I enter a value and then when I click on Enter, I want it to make something. My problem is that I have to press Enter twice to get the desired results.

    editText1.setOnKeyListener(new OnKeyListener() {
        public boolean onKey(View v, int keyCode, KeyEvent event) {
            // If the event is a key-down event on the "enter" button
            if ((event.getAction() == KeyEvent.ACTION_DOWN) &&
                (keyCode == KeyEvent.KEYCODE_ENTER)) {

              // Perform action on key press
              mWebView.loadUrl(editText1.getText().toString());
              mWebView.requestFocus(); 
              return true;
            }
            return false;
        }
    });
udondan
  • 57,263
  • 20
  • 190
  • 175
Alaoui Ghita
  • 1,859
  • 4
  • 22
  • 26

1 Answers1

1

I had a similar issue once before. Have you tested this on an actual phone, or are you just trying this in the emulator. I can not remember the specifics of my original experience, but I found that it was due to lag in the emulator. Try signing the app and sideloading it onto a phone to see if the desired effect happens. However, if that doesn't resolve it for you, check out this other post:

Android - Handle "Enter" in an EditText

Community
  • 1
  • 1
BMo
  • 331
  • 1
  • 2