简体   繁体   English

EditView单击即可执行操作

[英]EditView perform an action on click

I have an EditView and I have added : 我有一个EditView并且添加了:

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? 有什么解决办法,如果可以,我该怎么办?

EditText.OnEditorActionListener is what you are looking for, the API Documentation can be found here . 您正在寻找EditText.OnEditorActionListener这里可以找到API文档。 The action that will be called for the GO button is EditorInfo.IME_ACTION_GO . GO按钮将被调用的动作是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;
        }
});

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM