search

Home  >  Q&A  >  body text

Android edittext 软键盘互相抢夺焦点,onFocusChange方法会回调多次?

protected static class BlurChangeListener implements OnFocusChangeListener {
        

        @Override
        public void onFocusChange(View v, boolean hasFocus) {
            if (!hasFocus) {
                //do something
            }
        }
    }
 

RT,怎么处理让其只是光标不在edittext上才回调?

PHP中文网PHP中文网2772 days ago630

reply all(3)I'll reply

  • PHP中文网

    PHP中文网2017-04-17 17:57:22

    Finally, it was handled through the handler. When there is a keyboard, this method is continuously called back, so everything mentioned above has problems.

    reply
    0
  • 巴扎黑

    巴扎黑2017-04-17 17:57:22

    Only one gets focus by default?

    reply
    0
  • 天蓬老师

    天蓬老师2017-04-17 17:57:22

    Edittext does not steal focus.
    Looking at your code, I guess you have set multiple Edittexts to this listener.
    Then you should write it like this, like onclickListener

    @Override
        public void onFocusChange(View v, boolean hasFocus) {
            if (!hasFocus) {
                if(v.getId == R.id.et_id){
                    //do something
                }
            }
        }

    I’ve been reading about the problem for a long time. If it has been solved long ago, I suggest you answer the question yourself and adopt it. This will be better for everyone

    reply
    0
  • Cancelreply