Android 自动单击警报对话框按钮
这是我的密码。现在,如何在警报对话框按钮中自动单击积极按钮Android 自动单击警报对话框按钮,android,android-alertdialog,Android,Android Alertdialog,这是我的密码。现在,如何在警报对话框按钮中自动单击积极按钮 static void show(final Context context, String content, final String downloadUrl) { if (isContextValid(context)) { new AlertDialog.Builder(context) .setIcon(R.drawable.ic_support)
static void show(final Context context, String content, final String downloadUrl) {
if (isContextValid(context)) {
new AlertDialog.Builder(context)
.setIcon(R.drawable.ic_support)
.setTitle(R.string.android_auto_update_dialog_title)
.setMessage(content)
.setPositiveButton(R.string.android_auto_update_dialog_btn_download, new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int id) {
goToDownload(context, downloadUrl);
}
})
.setCancelable(false)
.show();
}
}
你可以这样做
dialog.getButton(DialogInterface.BUTTON_POSITIVE).performClick();
您的代码应该是这样的
AlertDialog dialog = new AlertDialog.Builder(context)
.setIcon(R.drawable.ic_support)
.setTitle(R.string.android_auto_update_dialog_title)
.setMessage(content)
.setPositiveButton(R.string.android_auto_update_dialog_btn_download, new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int id) {
goToDownload(context, downloadUrl);
}
})
.setCancelable(false)
.show();
我是android新手。。。。。如何添加上述代码。请告诉我你是如何在不到一分钟的时间内测试的?