I have an app where there is a AutoCompleteTextView. On every text change event, the app goes on to the web to retrieve some content from the internet and populates the dropdown for the TextView. I have used AsyncTask for doing the web content read. However, if new text is typed before the content is received and populated, the app is hanging till the old content is fetched. Is there a way to get around the problem?
My AsyncTask is as follows,
private class GetSuggestions extends AsyncTask<String, Void, String> {
@Override
protected String doInBackground(String... params) {
System.out.println("Suggestions Called()");
doSearch(params[0]); // reads the web and populates the suggestions ArrayList
return null;
}
@Override
protected void onPostExecute(String result) {
System.out.println("Adapter Called() " + suggestions.size());
suggestionAdapter = new ArrayAdapter<String>(
getApplicationContext(), R.layout.list, suggestions);
searchText.setAdapter(suggestionAdapter);
}
}
Thx! Rahul.