Note that there are some explanatory texts on larger screens.

plurals
  1. POPopulating an autocompletetextview with results from a php powered webservice
    primarykey
    data
    text
    <p>I am trying to develop an app which updates an autocomplete view with json data from a webservice.</p> <p>Using a textwatcher, I check in the ontextchanged callback and create an asynctask object which makes a non-blocking call to the webservice to get the results. When text is entered, any running asynctask objects are cancelled and a new one is generated( since an asynctask is a sort of singleton and I cannot rerun it). </p> <p>The results are then added to the autocomplete view by clearing its ArrayAdapter and adding each new item.</p> <p>The problem is that the data is almost never retrieved from the server, be it due to the constant cancels or whatever.</p> <p>Is there correct solution for doing this, or has anybody ever achieved such a task succesfully?</p> <p>Below are the relevant code snippets. TextWatcher, </p> <pre><code>public void onTextChanged(CharSequence s, int start, int before, int count) { Log.i("Text watcher", suggestsThread.getStatus().toString()); if(s.length() &gt;= suggestions.getThreshold() &amp;&amp; suggestsThread.getStatus() != AsyncTask.Status.RUNNING) { suggestsThread.cancel(true); suggestsThread = new WertAgentThread(); suggestsThread.execute(s.toString()); } </code></pre> <p>}</p> <p>Updating the autocomplete task,</p> <pre><code>public void updateSuggestions(String[] suggestions) { if( suggestions != null) { try { for(int ctr = 0; ctr &lt; suggestions.length; ctr++) { this.logger.append(suggestions[ctr]); } suggestAdapter = new ArrayAdapter&lt;String&gt;(this, R.layout.suggestions, suggestions); this.suggestions.setAdapter(suggestAdapter); } catch(NullPointerException ex) { Log.e("Updating adapter", ex.toString()); } } </code></pre> <p>The updateSuggestions is called in the onPostExecute callback in the Asynctask. Appreciating your help in advance,</p> <p>Roland.</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.
    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