我有一个android应用程序,它的主要活动,数据从sqlite数据库改编,并显示在列表视图。我试图使用进度对话框在从数据库获取数据期间向用户显示“加载”消息。但对话不会消失。ProgressDialog不消失在Android应用程序
下面是代码:
public class BirthdayAlarmActivity extends ListActivity {
List listofAvailableBirthdays;
ProgressDialog pDialog;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.birthday_list);
listofAvailableBirthdays=new ArrayList();
ReinitializeList();
}
@Override
protected void onResume() {
ReinitializeList();
}
void ReinitializeList()
{
new LoadListView().execute();
if(listofAvailableBirthdays.size()>0)
{
//get ready the adapter
ArrayAdapter ara=
new MyArrayAdapter(BirthdayAlarmActivity.this,listofAvailableBirthdays);
//set the adapter
setListAdapter(ara);
}
}
public class LoadListView extends AsyncTask
{
//ProgressDialog pDialog;
@Override
protected void onPreExecute() {
// Showing progress dialog before sending http request
pDialog = new ProgressDialog(
BirthdayAlarmActivity.this);
pDialog.setMessage("Please wait..");
pDialog.setIndeterminate(true);
pDialog.setCancelable(false);
pDialog.show();
}
protected Void doInBackground(Void... unused) {
runOnUiThread(new Runnable() {
public void run() {
// increment current page
listofAvailableBirthdays.clear();
listofAvailableBirthdays=BirthdayHandler.GetTenBirthDays(BirthdayAlarmActivity.this);
}
});
return (null);
}
protected void onPostExecute(Void unused) {
// closing progress dialog
pDialog.dismiss();
}
}
+0
如果您在UI线程上运行doInBackground的所有代码,那么使用AsyncTask有什么意义? –
2012-03-18 10:23:26
+0
我是多线程的概念的新手,并从这个示例中学习它[http://www.androidhive.info/2012/03/android-listview-with-load-more-button/]。我该怎么办 ? –
2012-03-18 10:30:45