How to avoid getting both called: onItemClicked and onTextChanged on AutoCompleteTextView

前端 未结 2 635
情话喂你
情话喂你 2021-02-04 00:56

I have this code. When I choose an item from suggestion list, the onTextChanged happens first, then oItemClicked comes after that. Now I want when choosing a word, the \"onItemC

2条回答
  •  情歌与酒
    2021-02-04 01:04

    isPerformingCompletion() was added in API Level 3. It returns true after an item has been selected from the drop-down list and TextWatcher listeners are about to be triggered. In short, to avoid the behaviour described:

    public void onTextChanged(CharSequence s, int start, int before, int count) {
        if (autoCompleteView.isPerformingCompletion()) {
            // An item has been selected from the list. Ignore.
            return;
        }
    
        // Your code for a general case
    }
    

提交回复
热议问题