Immediately show autocomplete on Android

后端 未结 6 2224
鱼传尺愫
鱼传尺愫 2021-02-19 05:39

The Android autocomplete only starts after two letters. How can I make it so the list appears when the field is just selected?

6条回答
  •  时光说笑
    2021-02-19 06:26

    Extend the AutoCompleteTextView, overriding the enoughToFilter() methods and the threshold methods so that it doesn't replace the 0 threshold with a 1 threshold:

    public class MyAutoCompleteTextView extends AutoCompleteTextView {
    
        private int myThreshold;
    
        public MyAutoCompleteTextView(Context context) {
            super(context);
        }
    
        public MyAutoCompleteTextView(Context context, AttributeSet attrs, int defStyle) {
            super(context, attrs, defStyle);
        }
    
        public MyAutoCompleteTextView(Context context, AttributeSet attrs) {
            super(context, attrs);
        }
    
        @Override
        public void setThreshold(int threshold) {
            if (threshold < 0) {
                threshold = 0;
            }
            myThreshold = threshold;
        }
    
        @Override
        public boolean enoughToFilter() {
            return getText().length() >= myThreshold;
        }
    
        @Override
        public int getThreshold() {
            return myThreshold;
        }
    
    }
    

提交回复
热议问题