安卓:在overrided&QUOT隐藏键盘;完成"的EditText的关键preSS键盘、关键、QUOT、overrided

2023-09-05 10:59:48 作者:牵着蜗牛去散步

我已经用了一下安卓code覆盖完成按钮,在我的EditText领域:

I have used a bit of Android code to override the "Done" button in my EditText field:

   myEditField.setOnEditorActionListener(new TextView.OnEditorActionListener() {
        @Override
        public boolean onEditorAction(TextView v, int actionId, KeyEvent event) {
            if (actionId == EditorInfo.IME_ACTION_DONE) {

                mySubroutine();

                return true;
            }
            return false;
        }
    });

激活现场调出键盘和pressing完成评估mySubroutine()成功。但是,键盘不再消失,当我preSS完成。如何恢复这个默认行为的例行?

Activating the field calls up the keyboard, and pressing "Done" evaluates mySubroutine() successfully. However, the keyboard no longer goes away when I press "Done". How do I restore this default behaviour to the routine?

推荐答案

为什么不:

myEditField.setOnEditorActionListener(new TextView.OnEditorActionListener() { 
    @Override 
    public boolean onEditorAction(TextView v, int actionId, KeyEvent event) { 
        if (actionId == EditorInfo.IME_ACTION_DONE) { 

            mySubroutine(); 
        } 
        return false; 
    } 
}); 

刚刚返回false后,你处理你的code。这可能是PTED因为不管你的code(mySubroutine()),它还是会使用什么样的默认操作之后除$ P $。如果返回真,你是在告诉你是一个幸福codeR和一切需要做已经发生在你的mySubroutine()和默认操作不需要采取行动。

Just return false after you handle your code. This can be interpreted as no matter what your code (mySubroutine()) does it will still use the default action afterwards. If you return "true" you are telling that you are a happy coder and everything that needed to be done has happen in your mySubroutine() and the default action do not need to take action.