android: Softkeyboard perform action when Done key is pressed

后端 未结 4 1660
予麋鹿
予麋鹿 2020-12-12 20:05

I have an EditText. I want that after typing some text, when user presses the Done key of the softkeyboard, it should directly perform some search operation whi

4条回答
  •  既然无缘
    2020-12-12 21:05

    Try this

    This will work in both condition whether your keyboard is showing enter sign or next arrow sign

    YourEdittextName.setOnEditorActionListener(new TextView.OnEditorActionListener()
        {
            @Override
            public boolean onEditorAction(TextView v, int actionId, KeyEvent event)
            {
                if(actionId== EditorInfo.IME_ACTION_DONE||actionId==EditorInfo.IME_ACTION_NEXT)
                {
                    //Perform Action here 
                }
                return false;
            }
        });
    

    if u r facing red line then do this... import Keyevent and EditorInfo by pressing alt+enter then all the errors remove it will properly.......

提交回复
热议问题