我正在制作一个Android应用程序,我必须在android中使用进度对话框。我想在我点击登录按钮时加载进度图像。实际上我正在解析响应,我想要直到响应被解析的时候它应该显示进度对话框。任何帮助将不胜感激。 感谢。
答案 0 :(得分:1)
是的,你可以像下面的代码那样做并链接。 http://developer.android.com/reference/android/os/AsyncTask.html
private class DownloadFilesTask extends AsyncTask<URL, Integer, Long> {
protected Long doInBackground(URL... urls) {
int count = urls.length;
long totalSize = 0;
for (int i = 0; i < count; i++) {
totalSize += Downloader.downloadFile(urls[i]);
publishProgress((int) ((i / (float) count) * 100));
}
return totalSize;
}
protected void onProgressUpdate(Integer... progress) {
setProgressPercent(progress[0]);
}
protected void onPostExecute(Long result) {
showDialog("Downloaded " + result + " bytes");
}
}
答案 1 :(得分:1)
显示像这样的对话框
ProgressDialog pd=new ProgressDialog(context);
pd.setMessage("Loading..");pd.setTitle("Please wait");
Thread thread=new Thread(new Runnable() {
@Override
public void run() {
//do your parsing; //But do not update user interface here
handler1.sendEmptyMessage(1);
}
});
pd.show();
thread.start();
现在使用处理程序类
处理程序消息和解除对话框 private Handler handler=new Handler(){
//Handle message here and dismiss dialog box
};