Android.app.ProgressDialog
A dialog showing a progress indicator and an optional text message or view. Only a text message or a view can be used at the same time. The dialog can be made cancelable on back key press.
The progress range is 0..10000.
Android에서 Cancel 처리 방법에 대한 예제
아래코드는 AsyncTask에서 ProgressDialog가 cancel 버튼을 클릭했을때, cancel 처리를 하는 예제이다.
class MyTask extends AsyncTask<Void, Void, Void> {
private volatile boolean running = true;
private final ProgressDialog progressDialog = null;
public MyTask(Context ctx) {
// progressDialog = gimmeOne(ctx);
progressDialog.setCancelable(true);
progressDialog.setOnCancelListener(new OnCancelListener() {
@Override
public void onCancel(DialogInterface dialog) {
// actually could set running = false; right here, but I'll
// stick to contract.
cancel(true);
}
});
}
@Override
protected void onPreExecute() {
progressDialog.show();
}
@Override
protected void onCancelled() {
running = false;
}
@Override
protected Void doInBackground(Void... params) {
while (running) {
// does the hard work
}
return null;
}
// ...
}
See also
Favorite site
- Android Dialogs
- Android ProgressDialog
- Android ProgressBar와 ProgressDialog
- 안드로이드에서 파일을 받을 때 프로그래스바로 진행상태 보여주는 방법
- Android: Dialog, AlertDialog, ProgressDialog, DatePickerDialog, TimePickerDialog
- [추천] Download a file with Android, and showing the progress in a ProgressDialog 1
- Dialog및 ProgressDialog 하드웨어 Key 막기
References
-
Android_download_progress.pdf ↩