帮助 - 阅读所有相关线程,但我的 onPostExecute 没有被调用。
我正在尝试通过使用 AsyncTask 在单独的线程上运行列表构建器来为 AutoCompleteTextView 动态创建自动完成列表
这是基本代码....有什么想法吗?
_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);
}
}