Show all items in AutocompleteTextView without writing text

前端 未结 12 836
萌比男神i
萌比男神i 2020-12-29 01:05

I have a AutocompleteTextView and it works fine. When I write a word it shows the relevant result but I want to show all items without writing any word in AutocompleteTextVi

12条回答
  •  暗喜
    暗喜 (楼主)
    2020-12-29 01:59

    If other solutions does not work for you try this instead. Popup is displayed always on click.

       public class InstantAutoComplete extends AppCompatAutoCompleteTextView {
    
        public InstantAutoComplete(Context context) {
            super(context);
        }
    
        public InstantAutoComplete(Context arg0, AttributeSet arg1) {
            super(arg0, arg1);
        }
    
        public InstantAutoComplete(Context arg0, AttributeSet arg1, int arg2) {
            super(arg0, arg1, arg2);
        }
    
        @Override
        public boolean enoughToFilter() {
            return true;
        }
    
        @Override
        public boolean onTouchEvent(MotionEvent event) {
            if (event.getAction() == MotionEvent.ACTION_DOWN) {
                performClick();
            }
            return super.onTouchEvent(event);
        }
    
        @Override
        public boolean performClick() {
            if (getFilter() != null && !isPopupShowing()) {
                performFiltering(getText(), 0);
                showDropDown();
            }
            return super.performClick();
        }
    }
    

提交回复
热议问题