1

我有一个ProgressDialog包含按钮的“请稍候”,问题是当单击按钮时对话框被关闭(它消失),我怎样才能让对话框留在屏幕上

    // Please wait dialog
private void showWaitDialog() {
    prgDialg = new ProgressDialog(context);
    prgDialg.setTitle("Working...");
    prgDialg.setMessage("Please wait.");
    prgDialg.setCancelable(false);
    prgDialg.setButton("Do something", myListener);
    prgDialg.show();
}

// Click listener
public OnClickListener myListener = new OnClickListener(){

    @Override
    public void onClick(DialogInterface dialog, int which) {
        textViev1.setText("xxx");
    }
4

3 回答 3

-1
private void showWaitDialog() {
    prgDialg = new ProgressDialog(context);
    prgDialg.setTitle("Working...");
    prgDialg.setMessage("Please wait.");
    prgDialg.setCancelable(false);
    prgDialg.setNeutralButton("Do Something", new View.OnClickListener() {

    @Override
    public void onClick(DialogInterface dialog, int which) {
                textViev1.setText("xxx");
    }
    });
    prgDialg.show();
}
于 2013-07-10T08:40:23.947 回答
-1

prgDialg.setButton("做点什么", myListener); 不推荐使用上述方法 setButton(CharSequence text, DialogInterface.OnClickListener listener)。

您可以使用

private void showWaitDialog() {
    prgDialg = new ProgressDialog(this);
    prgDialg.setTitle("Working...");
    prgDialg.setMessage("Please wait.");
    prgDialg.setCancelable(false);
    prgDialg.setButton(DialogInterface.BUTTON_NEUTRAL, "Do something", this);
    prgDialg.show();
}

@Override
public void cancel() {

}

@Override
public void dismiss() {

}
于 2013-07-10T08:27:20.977 回答
-1

尝试这个

prgDialg.setButton("Do something", new DialogInterface.OnClickListener() 
    {
        public void onClick(DialogInterface dialog, int which) 
        {
            // Use either finish() or return() to either close the activity or just the dialog
            return;
        }
    });
于 2013-07-10T08:19:03.280 回答