1

I have made a webbrowser application for android (minSdkVersion 21) It is working fine but I have a little problem with the Keyboard and a button.

Here you can see the app there is a button when I click on GO it loads a page. But when i click on enter in my keyboard it does nothing.

enter image description here

I have tried the following:

  • KeyEvent.KEYCODE_ENTER
  • loadUrl

In my activity_main.xml

 <Button
                android:id="@+id/button"
                style="@style/Base.Widget.AppCompat.Button.Borderless"
                android:layout_width="80dp"
                android:layout_height="wrap_content"
                android:layout_alignParentRight="true"
                android:imeOptions="actionGo"
                android:layout_centerVertical="true"
                android:text="Go"/>

I think there is no problem so far with my activity_main.xml

And in my MainActivity.java i have:

Button button;  
button = (Button) findViewById(R.id.button);

     button.setImeActionLabel("", KeyEvent.KEYCODE_ENTER);
                     webView.loadUrl("");
                     return true;

When i click on enter on my keyboard i want to have the same function as my button "GO" (it needs to load a page)

Deniz
  • 107
  • 2
  • 15
  • Possible duplicate of [Use "ENTER" key on softkeyboard instead of clicking button](https://stackoverflow.com/questions/4451374/use-enter-key-on-softkeyboard-instead-of-clicking-button) – John Joe May 23 '17 at 12:33
  • 1
    Dont think so the other post says instead what i want is that those 2 (button and keyboard key: ENTER load a page) – Deniz May 23 '17 at 12:36
  • The link I sent will active the button when the enter key is pressed. – John Joe May 23 '17 at 12:39

1 Answers1

0

paste this code. here edit text is editText where your are taking the input.

edittext.setOnEditorActionListener(new TextView.OnEditorActionListener() {
        @Override
        public boolean onEditorAction(TextView v, int actionId, KeyEvent event) {
            if ((actionId == EditorInfo.IME_ACTION_DONE)) {
                //Your Action as go button
            }
            return false;
        }
    });
xbadal
  • 1,284
  • 2
  • 11
  • 24