本文介绍了Android ProgressDialog无法添加“取消”按钮的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想在进度对话框中添加一个取消按钮,但是我无法编译代码。 IDE(eclipse)的意思是代码中有错误,但是我不知道这是怎么回事?

I want to add a cancel button to my progress dialog but I can't compile the code. The IDE (eclipse) it's saying that there is an error in the code but I don't know what's wrong?

ProgressDialog ASYN_DIALOG = new ProgressDialog(getBaseContext());
ASYN_DIALOG.setMessage("Awaiting...");
ASYN_DIALOG.setButton("Cancel", new OnClickListener() {

    @Override
    public void onClick(DialogInterface dialog, int which) {
       Log.e("ANDR: ", "Cancel clicked !");
    }
});

我正在使用API​​ lvl 10(Android 2.3.3)

I'm using API lvl 10 (Android 2.3.3)

推荐答案

您使用的 setButton 方法已弃用(尽管它仍然可以使用)。另外,您可能需要在显示对话框之前添加按钮。尝试:

The setButton method you are using is deprecated (although it should still work). Also, you might want to add the button before showing the dialog. Try:

myDialog = new ProgressDialog(this);
myDialog.setMessage("Loading...");
myDialog.setCancelable(false);
myDialog.setButton(DialogInterface.BUTTON_NEGATIVE, "Cancel", new DialogInterface.OnClickListener() {
    @Override
    public void onClick(DialogInterface dialog, int which) {
        dialog.dismiss();
    }
});
myDialog.show();

这篇关于Android ProgressDialog无法添加“取消”按钮的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-20 12:11