Dynamically updating an AutoCompleteTextView adapter

后端 未结 5 1575
执笔经年
执笔经年 2020-11-28 23:20

I want to periodically change the suggestions given by an AutoCompleteTextview by getting the list from a RESTful web service, and can\'t get it working smoothly. I set up a

5条回答
  •  余生分开走
    2020-11-28 23:49

    Since i am not able to add a comment, i am giving a new answer There is no need for clearing the adapter or calling adapter.getFilter().filter(...)... To dynamically update an AutoCompleteTextView adapter, simply add the new item to the adapter and setAdapter again. For the example given in the original question, i tried the following and it works (the code below does not show the initial setting of the adapter, since multiple answers here cover that. This just shows updating the adapter dynamically). The adapter update can be alongside the code that updates the List associated with the ArrayAdapter.

        adapter.add(String newSuggestion); // this goes inside a loop for adding multiple suggestions
        speciesName.setAdapter(adapter) ; // speciesName is an AutoCompleteTextView as given in the original question.
    

提交回复
热议问题