Android: AutoCompleteTextView show suggestions when no text entered

后端 未结 14 1936
-上瘾入骨i
-上瘾入骨i 2020-11-27 11:20

I am using AutoCompleteTextView, when the user clicks on it, I want to show suggestions even if it has no text - but setThreshold(0) works exactly

14条回答
  •  鱼传尺愫
    2020-11-27 12:17

    Destil's code works just great when there is only one InstantAutoComplete object. It didn't work with two though - no idea why. But when I put showDropDown() (just like CommonsWare advised) into onFocusChanged() like this:

    @Override
    protected void onFocusChanged(boolean focused, int direction,
            Rect previouslyFocusedRect) {
        super.onFocusChanged(focused, direction, previouslyFocusedRect);
        if (focused) {
            performFiltering(getText(), 0);
            showDropDown();
        }
    }
    

    it solved the problem.

    It is just the two answers properly combined, but I hope it may save somebody some time.

提交回复
热议问题