AutoCompleteTextView item selection programmatically

前端 未结 9 2052
故里飘歌
故里飘歌 2021-02-18 14:41

I have an autocomplete text view that is filled with cities from an sqlite database that calls an async task on item click, recently I added an option to detect my location usin

9条回答
  •  温柔的废话
    2021-02-18 14:57

    A solution were you don't need to change your API level.

    automCompleteTextView.setAdapter(adapter);        
    // set default selection, filtering is active so all items is not visible in drop-down menu
    automCompleteTextView.setText(automCompleteTextView.getAdapter().getItem(0).toString());
    // change filtering for the adapter so all items can be visible in drop-down menu
    adapter.getFilter().filter(null);
    

    one-liner for the same job but requires higher API level

    automCompleteTextView.setText(automCompleteTextView.getAdapter().getItem(0).toString(), false);
    

提交回复
热议问题