这与AsyncTask帮助(智能底色线程)和ProgressDialog
时候做的AsyncTask开始,我们提出一个progressdialog与不确定状态,一旦任务完成后,我们关闭对话框。
示例代码
什么适配器确实在这个例子就明白了,你需要使用的AsyncTask以显示该进程的对话框并不重要,更重要的。
private class PrepareAdapter1 extends AsyncTask<Void,Void,ContactsListCursorAdapter > {
ProgressDialog dialog;
@Override
protected void onPreExecute() {
dialog = new ProgressDialog(viewContacts.this);
dialog.setMessage(getString(R.string.please_wait_while_loading));
dialog.setIndeterminate(true);
dialog.setCancelable(false);
dialog.show();
}
/* (non-Javadoc)
* @see android.os.AsyncTask#doInBackground(Params[])
*/
@Override
protected ContactsListCursorAdapter doInBackground(Void... params) {
cur1 = objItem.getContacts();
startManagingCursor(cur1);
adapter1 = new ContactsListCursorAdapter (viewContacts.this,
R.layout.contact_for_listitem, cur1, new String[] {}, new int[] {});
return adapter1;
}
protected void onPostExecute(ContactsListCursorAdapter result) {
list.setAdapter(result);
dialog.dismiss();
}
}
亲爱的Pentium10,谢谢你的回答!这可能对我有很大帮助,尽管我的应用程序中耗时的部分是对ListAdapter的getView()方法的调用。但无论如何:是否有必要为onCreate方法中的ListView提供适配器?他们是怎么做到的?有一个空虚拟列表或什么?另外,这个加载动画的白色屏幕只是一个覆盖整个屏幕的Progressdialog?提前致谢! – janoliver 2010-11-20 19:27:08
您可以在列表视图上提供适配器,即使它是空的。然后,您可以稍后添加项目,并且可以调用notifyDatasetChanged事件来刷新ListView。您可以将视图缓存在某个类对象中供以后使用。 – Pentium10 2010-11-20 20:08:41