Android - onTextChanged() called on when phone orientation is changed

后端 未结 2 1333
梦谈多话
梦谈多话 2021-02-06 02:32

I tried to implement search using EditText. whenever a text is typed in the EditText request is sent with the typed text in onTextChanged()

2条回答
  •  故里飘歌
    2021-02-06 02:48

    I've got this problem just. So I moved addTextChangedListener to the post method of EditText in the onCreateView:

    public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
    
        ...
    
        EditText mSearchQuery = findViewById(R.id.search_query);
        mSearchQuery.post(new Runnable() {
                @Override
                public void run() {
                    mSearchQuery.addTextChangedListener(new TextWatcher() {
                        @Override
                        public void beforeTextChanged(CharSequence s, int start, int count, int after) {
                        }
    
                        @Override
                        public void onTextChanged(CharSequence s, int start, int before, int count) {
                            //Some stuff
                        }
    
                        @Override
                        public void afterTextChanged(Editable s) {
                        }
                    });
                }
            });
    }
    

提交回复
热议问题