0

I have a SearchView in ActionBar and I'm using onQueryTextListener with it. I have a Listview in activity's layout to which the ActionBar belongs. There are two Textviews in ListView. So, as user enter text into searchview, a web query(api) is performed on the text and the results(array) received are used to populate the listview. Just like AutoCompleteTextView but instead displaying results in listview.

I am using a HandlerThread to perform this query and populating the listview and I have implemented it in onQueryTextChange which is working.

But, the problem is that it takes long time to display results. The results are displayed after user is done entering input. However, I want results to be displayed as user enter text(Like Google suggest). How can I do this?

harry perry
  • 113
  • 1
  • 8
  • No, no, no, dont use any HandlerThread, see Filter class and Filterable interface – pskink Dec 27 '14 at 13:41
  • See my answer here: http://stackoverflow.com/questions/19858843/how-to-dynamically-add-suggestions-to-autocompletetextview-with-preserving-chara to know how to easily implement filtering with a CursorAdapter – pskink Dec 27 '14 at 13:46
  • @pskink What are the scenarios where HandlerThreads can be used and why HandlerThreads isn't a good idea in this case? – harry perry Dec 27 '14 at 18:04
  • See http://androidxref.com/5.0.0_r2/xref/frameworks/base/core/java/android/widget/Filter.java, line 104 – pskink Dec 27 '14 at 18:13

1 Answers1

0

I imagine Google uses cached results on their servers to speed up the response to queries. You could use something like MemCache or Varnish to provide results faster. If the results require searches you could also improve the speed by using a search engine like Apache Solr or Lucene.

Google will also have very good server infrastructure with cached results being located all over the world so always near the user. The results will probably vary from server to server so that they give what local users want. I remember calculating a few years back based on trying to improve response times for online gaming that Europe is something like a tenth of a second from North America.

You can also fake this information. You can download results that you anticipate a user would want on to their device and fill the autocomplete from a database on the device. A request can also be sent to the server at the same time and the autocomplete results updated once the response is received from the server. This to some extent depends on the complexity of what you are searching. If there are only a limited number of results you could easily store them all on the device.

TTransmit
  • 3,022
  • 2
  • 21
  • 39