Note that there are some explanatory texts on larger screens.

plurals
  1. PORefresh ArrayAdapter dynamically
    primarykey
    data
    text
    <p>I have an Activity with an AutoComplete box on it. Whenever the text changes, I want to call a web service and populate the ArrayAdapter with the new String[] returned. This part all works great, except the list in the UI isn't being refreshed when there are all new values in String[] schools. The original list populated in my onCreate always remains. </p> <p>I read somewhere I needed to update it on the same thread the UI is running on, so I tried the Runnable listed in my code below. But that, as well as just updating my class variable schools does not work alongside notifyOnDataSetChange()</p> <p>Where am I going wrong?</p> <pre><code>@Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.main); schools = SchoolProxy.search("Co"); autoCompleteAdapter = new ArrayAdapter(this,android.R.layout.simple_dropdown_item_1line, schools); autoComplete = (AutoCompleteTextView) findViewById(R.id.edit); autoComplete.addTextChangedListener(textChecker); autoComplete.setAdapter(autoCompleteAdapter); } ... .... ... final TextWatcher textChecker = new TextWatcher() { public void afterTextChanged(Editable s) {} public void beforeTextChanged(CharSequence s, int start, int count, int after) {} public void onTextChanged(CharSequence s, int start, int before, int count) { schools = SchoolProxy.search(s.toString()); runOnUiThread(updateAdapter); } }; private Runnable updateAdapter = new Runnable() { public void run() { autoCompleteAdapter.notifyDataSetChanged(); } }; </code></pre> <p>As a less important side note, if each item in schools has a name \n city,state. Is it possible to have the city &amp; state on a second line within the auto drop down box? Just for formatting purposes. Would look cleaner if I could. </p> <p>Thank you!</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload