-1

Here is my code . and now how to click on POSITIVE button automatically in alert dialog button.

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();
}
}
Ronak Thakkar
  • 2,515
  • 6
  • 31
  • 45

1 Answers1

0

you can do it like this

dialog.getButton(DialogInterface.BUTTON_POSITIVE).performClick();

your code should be like this

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();
akshay_shahane
  • 4,423
  • 2
  • 17
  • 30