Search code examples
javaandroidxmleditview

EditView perform an action on click


I have an EditView and I have added :

android:imeActionLabel="Go"

This is showing "Go" button in keyboard, but I don't know how to perform an action when user clicks "Go" button.

Is there any solution about this, if yes how can I do it?


Solution

  • EditText.OnEditorActionListener is what you are looking for, the API Documentation can be found here. The action that will be called for the GO button is EditorInfo.IME_ACTION_GO. I have provided a brief example below.

    editText.setOnEditorActionListener(new OnEditorActionListener()
    {
            @Override
            public boolean onEditorAction(TextView v, int actionId, KeyEvent event)
            {
                if(actionId==EditorInfo.IME_ACTION_GO)
                {
                        //Handle go button pressed
                }
                return false;
            }
    });