How to detect if users stop typing in EditText android

前端 未结 7 1360
长情又很酷
长情又很酷 2020-12-24 14:31

I have an EditText field in my layout. I want to perform an action when the user stops typing in that edittext field. I have implemented TextWatcher and use its functions

7条回答
  •  借酒劲吻你
    2020-12-24 15:12

    You could use a focus change listener. If the edittext has focus then assume user still editing otherwise they have stopped and you can perform your action:

        EditText et = new EditText(mContext);
        et.setOnFocusChangeListener(new View.OnFocusChangeListener() {
            @Override
            public void onFocusChange(View view, boolean hasFocus) {
                if (hasFocus) {
                    //user has focused
                } else {
                    //focus has stopped perform your desired action
                }
            }
        });
    

提交回复
热议问题