You are viewing our old blog site. For latest posts, please visit us at the new space. Follow our publication there to stay updated with tech articles, tutorials, events & more.

Android Auto Complete with Real time suggestions

4.50 avg. rating (90% score) - 2 votes
In an android app, when we attach an AutoCompleteTextView to display suggestions while a user is typing, we can fetch the list of suggestions in two ways. One way is to store the data in a local database and fetch it using a search query on the search keyword entered by the user. Another way is to fetch list of suggestions in real time, by generating a search url with the search keyword and hitting the web service. In the second approach, we fetch data directly from server, so whenever the list of suggestions changes, it gets reflected immediately in the app. Whereas in the first one, we need either a trigger based pull to update the list it in the app or wait for another app release to be published. Also, if the suggestion set is huge, the build size increases accordingly.
But there are some key concerns when fetching suggestions from a web service. We have to ensure that as the user types non stop, we do not overwhelm servers as well as mobile devices with expensive and unnecessary network calls. The previous pending requests should get cancelled with every new letter appended to the search string. And the responses should get cached so that the subsequent requests get served locally.
Thus, to implement an AutoCompleteTextView in an optimized way, we have built a Suggestor widget. It provides a CustomAutoCompleteEditText that shows completion suggestions automatically while the user is typing. The list of suggestions is displayed in a dropdown menu from which the user can choose an item to replace the contents of the edit box with.
The library provides automatic caching of responses which reduces the number of network hits for a particular search query. You can clear the cache explicitly. It also provides multithreading, so you can plug more than one widgets on one screen and send different requests at one time and get results without any conflicts.
For more details, please visit
Posted in Mobile