Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>It seems that the request to the suggestion content provider is not run on the UI thread, anyway, according to this answer: <a href="https://stackoverflow.com/a/12895381/621690">https://stackoverflow.com/a/12895381/621690</a> . If you can change your http request you could simply call it blocking inside the query method. Might help to listen for interruptions or other signals (custom ones maybe) to stop unnecessary requests.</p> <p>Another option - if you do not want to change any request classes that are already asynchronous (like if you are using Robospice) - should be to just return the MatrixCursor reference and populate it later on. The AbstractCursor class already implements the Observer pattern and sends out notifications in case of changes. If the search system is listening it should handle any changes in the data. I have yet to implement that myself so I cannot confirm that it will work out as nicely as I picture it. (Have a look at CursorLoader's source for more inspiration.)</p> <p>And, anyway, isn't that the whole point of a cursor? Otherwise we could simply return a list with data.</p> <p>UPDATE: For me, using a MatrixCursor didn't work out. Instead, I have implemented two other solutions:</p> <ol> <li>Using the AutoCompleteTextField in combination with a custom subclass of ArrayAdapter which itself uses a custom subclass of Filter. The method <code>Filter#performFiltering()</code> (which I override with the synchronous call to the remote service) is called asynchronously and the UI thread is not blocked.</li> <li><p>Using the SearchWidget with a SearchableActivity and a custom ArrayAdapter (without custom Filter). When the search intent comes in, the remote request is started (Robospice) and when it comes back via callback, I call the following custom method on my <code>ArrayAdapter&lt;Tag&gt;</code> subclass:</p> <pre><code>public void addTags(List&lt;Tag&gt; items) { if (items != null &amp;&amp; items.size() &gt; 0) { if (Build.VERSION.SDK_INT &lt; Build.VERSION_CODES.HONEYCOMB) { super.setNotifyOnChange(false); for (Tag tag : items) { super.add(tag); } super.notifyDataSetChanged(); } else { super.addAll(items); } } } </code></pre></li> </ol> <p>This method takes care of triggering the notifications on the adapter and thus the search result list.</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