我的应用程序有一个包含3 ViewGroups的ViewFlipper。每个ViewGroup interaction都依赖于数据库中的数据。我使用AsyncTask从数据库中读取数据,并在读取完成后返回一个游标。在执行AsyncTask之前,我只想在ViewFlipper中显示一个单独的视图,上面写着“正在加载数据,请稍候。”
发布于 2011-07-12 20:15:14
在onPreExecute()中显示进度对话框,并在onPostExecute()中关闭它。就像这样,
private class MyAsyncTask extends AsyncTask<Integer, Integer, Integer[]> {
private ProgressDialog myWait = null;
// This is on the UI thread itself
protected void onPreExecute() {
myWait = new ProgressDialog(MainActivity.this);
myWait.setMessage("Loading data, please wait");
myWait.setCancelable(false);
myWait.show();
}
// Separate worker thread is used here
protected Integer[] doInBackground(Integer...params) {
//do the database loading
return <your result - goes to onPostExecute>;
}
// This is on the UI thread itself
protected void onPostExecute(Integer[] resultCell) {
if (myWait != null) {
myWait.dismiss();
}
}
}发布于 2011-07-12 20:01:07
是的,你可以使用progressDialog。像这样做,
progressDiaolg=ProgressDialog.show(Activity.this,"","Loading Images...");
final Thread t= new Thread(new Runnable() {
public void run() {
Log.i("Inside Thread", "Downloading Images...");
downloadImages();
handler.sendEmptyMessage(0);
}
});
t.start();
handler = new Handler() {
@Override
public void handleMessage(Message msg) {
try {
progressDiaolg.dismiss();
} catch (IllegalArgumentException e) {
e.printStackTrace();
}
}
};我对异步任务没有概念。因此,请尝试相应地修改此代码段。
https://stackoverflow.com/questions/6663694
复制相似问题