进度对话框启动另一个AlertDialog

时间:2013-07-10 17:00:16

标签: android progress-bar progressdialog

我想在进度条达到100%后显示另一条警告消息(警告框/警告对话框)。我怎么做?

还有什么方法可以设置那个盒子(或两个盒子)的样式?

以下是我的ProgressBar代码:

public class MainActivity extends Activity {

Button progress_button;
ProgressDialog pro_dialog;
Handler pro_handler;
int progress;
private static final int MAX_PROGRESS = 100; 


    @Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main_activity);

// intiliazing the buttons
progress_button = (Button) findViewById(R.id.button1);
progress_button.setOnClickListener(new OnClickListener() {

  @Override
  public void onClick(View v) {
   // Creating progress dialog interface setting
   // title,progressstyle,max_progress

pro_dialog = new ProgressDialog(MainActivity.this);
pro_dialog.setTitle("Making everything OK is in progress! Please be patient.");
pro_dialog.setProgressStyle(ProgressDialog.STYLE_HORIZONTAL);
pro_dialog.setMax(MAX_PROGRESS);

progress = 0;
pro_dialog.show();
pro_dialog.setProgress(0);
pro_handler.sendEmptyMessage(0);

  }
 });

 // set onclick listener for buttons

  pro_handler = new Handler() {
   @Override
   public void handleMessage(Message msg) {
    super.handleMessage(msg);
    if (progress >= MAX_PROGRESS) {
     pro_dialog.dismiss();
    } else {
     progress++;
     pro_dialog.incrementProgressBy(2);
     pro_handler.sendEmptyMessageDelayed(0, 100);
    }

   }
  };
 }

1 个答案:

答案 0 :(得分:0)

首先,如果你可以替换它会更有意义:

pro_dialog.incrementProgressBy(2);

用这个:

pro_dialog.setProgress(progress);

当前代码在进度变量达到MAX_PROGRESS后解除对话框,但进度对话框不显示此变量的当前值。

如果您想显示AlertDialog,您可以在“pro_dialog.dismiss()”之后执行此操作。

进展情况对话框样式已被讨论here