我已经开发了 android 应用程序,因为我正在使用 Autocompleate textview 来加载联系人。它工作正常,但由于在 onCreate 方法中加载所有联系人,活动打开速度变慢。我想知道如何在后台将联系人加载到 Autocpleate textview
问问题
225 次
1 回答
1
使用 anAsynctask
在后台初始化自动完成适配器:
final AutoCompleteTextView vTextView = findViewById(R.id.auto_text);
new AsyncTask<Void, Void, List<String>>() {
@Override
protected List<String> doInBackground(Void... pVoids) {
List<String> contacts = new ArrayList<String>();
//--read contacts---
return contacts;
}
@Override
protected void onPostExecute(List<String> result) {
ArrayAdapter<String> vAdapter = new ArrayAdapter<String>(getApplicationContext(),
android.R.layout.simple_dropdown_item_1line);
vAdapter.addAll(result);
vTextView.setAdapter(vAdapter);
}
}.execute();
于 2013-07-22T10:44:52.013 回答