EditView perform an action on click

假装没事ソ 提交于 2019-12-13 07:37:53

问题


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?


回答1:


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;
        }
});


来源:https://stackoverflow.com/questions/18219340/editview-perform-an-action-on-click

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!