AutoCompleteTextView not showing any drop down items

前端 未结 5 1575
[愿得一人]
[愿得一人] 2021-01-17 17:31

My XML:



        
5条回答
  •  独厮守ぢ
    2021-01-17 17:55

    I just saw your other question before seeing this one. I was struggling with autocomplete for some time and I almost reverted to your new implementation of downloading all the keywords until I finally got it to work. What I did was;

    //In the onCreate
    //The suggestArray is just a static array with a few keywords
    this.suggestAdapter = new ArrayAdapter(this, this.suggestionsView, suggestArray);
    //The setNotifyOnChange informs all views attached to the adapter to update themselves 
    //if the adapter is changed
    this.suggestAdapter.setNotifyOnChange(true);
    

    In my textwatcher's onTextChanged method, I get the suggests using an asynctask

    //suggestsThread is an AsyncTask object
    suggestsThread.cancel(true);
    suggestsThread = new WertAgentThread();
    suggestsThread.execute(s.toString());
    

    In the AsyncTask's onPostExecute I then update the autocompletetextview

    //suggestions is the result of the http request with the suggestions
    this.suggestAdapter = new ArrayAdapter(this, R.layout.suggestions, suggestions);
    this.suggestions.setAdapter(this.suggestAdapter);
    //notifydatasetchanged forces the dropdown to be shown.
    this.suggestAdapter.notifyDataSetChanged();
    

    See setNotifyOnChange and notifyDataSetChanged for more information

提交回复
热议问题