- AsyncTask:onPostExecute
- _artist = (AutoCompleteTextView)findViewById(R.id.artist);
- _artist.addTextChangedListener(new TextWatcher()
- {
- public void afterTextChanged(Editable s)
- {
- _artist.setAdapter(null);
- _fetcher = new AutoCompleteFetcher(_artist);
- _fetcher.execute();
- }
- }
- public class AutoCompleteFetcher extends AsyncTask<Void, Void, Void>
- {
- private AutoCompleteTextView _textView;
- private String[] _matches;
- public AutoCompleteFetcher(AutoCompleteTextView v)
- {
- super();
- _textView = v;
- }
- protected Void doInBackground(Void... v)
- {
- _matches = _getMatches();
- return null;
- }
- private String[] _getMatches()
- {
- // fill the list....... code removed here
- // returns populated String[]
- }
- @Override
- protected void onPostExecute(Void result)
- {
- ArrayAdapter<String> adapter =
- new ArrayAdapter<String>(_textView.getContext(),
- android.R.layout.simple_list_item_1,_matches);
- _textView.setAdapter(adapter);
- }
- }
- public class AutoCompleteFetcher extends AsyncTask<Void, Void, String[]>
- {
- private AutoCompleteTextView _textView;
- public AutoCompleteFetcher(AutoCompleteTextView v)
- {
- super();
- _textView = v;
- }
- @Override
- protected String[] doInBackground(Void... v)
- {
- return _getMatches();
- }
- private String[] _getMatches()
- {
- // fill the list....... code removed here
- // returns populated String[]
- // TODO: it seems like this method should really just be moved into
- // doInBackground(). That said, I don't think this is your problem.
- }
- @Override
- protected void onPostExecute(String[] result)
- {
- ArrayAdapter<String> adapter =
- new ArrayAdapter<String>(_textView.getContext(),
- android.R.layout.simple_list_item_1, result);
- _textView.setAdapter(adapter);
- }
- }