问题描述
我有一个列表视图的活动。当我把这个活动的活动时间约3-5秒出现并显示列表视图。这看起来好像按钮一直没有pssed加载活动$ P $,我想同时显示该加载一个progressdialog但不能弄明白。
I have an activity with a listview. When I call this activity the activity takes about 3-5 seconds to appear and display the listview. It looks as if the button has not been pressed to load the activity, i would like to display a progressdialog while this loads but can't figure it out.
ProgressDialog progress;
progress = ProgressDialog.show(this, "Loading maps!",
"Please wait...", true);
// sort out track array
getTracks();
progress.dismiss();
我做了上述与列表视图,但该对话框从未展示活动的OnCreate()?
I did the above on the oncreate() of the activity with the listview but the dialog never shows?
我想是要显示在活动A进度对话框当按钮是pressed然后解雇一旦活动B被加载并显示?
What I would like is to show the progress dialog on Activity A when the button is pressed and then dismiss once Activity B is loaded and displayed?
感谢
推荐答案
您需要执行的AsyncTask或简单的Java线程。与AsyncTask的去现在。
You need to implement AsyncTask or simple JAVA threading. Go with AsyncTask right now.
-
上preExecute()
- 在这里显示对话框 -
doInBackground()
- 调用getTracks() -
onPostExecute()
- ListView中显示曲目并关闭对话框
onPreExecute()
- display dialog heredoInBackground()
- call getTracks()onPostExecute()
- display tracks in ListView and dismiss dialog
例如:
private static class LoadTracksTask extends AsyncTask<Void, Void, Void> {
ProgressDialog progress;
@Override
protected void onPreExecute() {
progress = new ProgressDialog(yourActivity.this);
progress .setMessage("loading");
progress .show();
}
@Override
protected Void doInBackground(Void... params) {
// do tracks loading process here, don't update UI directly here because there is different mechanism for it
return null;
}
@Override
protected void onPostExecute(Void result) {
// write display tracks logic here
progress.dismiss(); // dismiss dialog
}
}
一旦你与定义你的AsyncTask类来完成,只需调用执行内部
的onCreate()
任务的execute()$ C $您的AsyncTask的C>方法。
Once you are done with defining your AsyncTask class, just execute the task inside onCreate()
by calling execute()
method of your AsyncTask.
例如:
new LoadTracksTask().execute();
这篇关于对于Android版的Listview进度对话框的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!