-->

EditView中执行的点击动作(EditView perform an action on cli

2019-10-29 19:48发布

我有一个EditView ,我还补充说:

android:imeActionLabel="Go"

这显示“转到”按钮键盘,但我不知道如何当用户点击“转到”按钮执行的操作。

有没有这方面有任何解决方案,如果是我该怎么办呢?

Answer 1:

EditText.OnEditorActionListener是你在找什么,API文档可以发现在这里 。 将要呼吁GO按钮的动作是EditorInfo.IME_ACTION_GO 。 我在下面提供了一个简单的例子。

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


文章来源: EditView perform an action on click