Reputation: 4422
My app uses data from a web server. On a website you can get autocomplete using some ajax calls which takes milli seconds to function. but in case of android i need to get all the key words from the site, store them in an array, make n adapter and set it to the AutoCompleteTextView. the problem is i have some 10K keywords on the server, so fetching such a huge data is a problem. So is there any other way to achieve autocomplete in my case?? thank you
Upvotes: 0
Views: 1063
Reputation: 895
Wouldn't it be a better idea to make an autocomplete similar to the one implemented on the website, i.e when a user types a certain number of characters, the suggestions are fetched and displayed in the dropdown. I believe that the average user would use at most 100 of the keywords( depending on the app you are making). That is what I am doing in my own app which has similarities with what you are trying to achieve. I ofcourse use an AsyncTask to fetch the suggestions.
If you must download all the 10k keywords, why not just make a static array with the keywords( assuming they do not change in the db).
Upvotes: 0
Reputation: 27777
You are clearly going to have to prefetch the data in a non-UI thread so as not to ANR the app, and make it accessible in the form of some sort of local cache or service so as not to fetch the same data repeatedly.
Options in order of least complex to most complex:
AsyncTask
and store the results in a static variable of some sort.AsyncTask
or similar concept like in (1), but store the results in a cache, like those found in Guava: http://code.google.com/p/guava-libraries/wiki/CachesExplainedUpvotes: 2