Autocompletion delay

前端 未结 4 509
予麋鹿
予麋鹿 2020-12-17 06:33

I\'ve got to set an autocompletion for my application.

I\'ve already understood the AutoCompleteTextView operation, but I\'d like to dynamically modify the Stri

4条回答
  •  没有蜡笔的小新
    2020-12-17 07:06

    I'd keep a long named lastPress as a field on my TextWatcher. When you press a key, set lastPress = System.currentTimeMillis(). Then just wrap your entire onTextChanged in a if with condition if(System.currentTimeMillis() - lastPress>500) and set lastPress again in that if.


    new TextWatcher(){
        long lastPress = 0l;
        @Override
        public void onTextChanged(CharSequence s,
                 int start, int before, int count){
            if(System.currentTimeMillis() - lastpress > 500){
                lastPress= System.currentTimeMillis();
                GetAutocompletion ac = new GetAutocompletion();
                ac.execute(zipBox.getText().toString());
            }
        }
        // Other methods to implement
    }
    

提交回复
热议问题