Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>Android is not always conventional. You can't show a dialog and wait for it to be displayed, then do something.</p> <p>You need to show a dialog, and respond to the yes / no buttons in a callback.</p> <p>Something like this is one solution:</p> <pre><code>/** * Display a confirm dialog. * @param activity * @param title * @param message * @param positiveLabel * @param negativeLabel * @param onPositiveClick runnable to call (in UI thread) if positive button pressed. Can be null * @param onNegativeClick runnable to call (in UI thread) if negative button pressed. Can be null */ public static final void confirm( final Activity activity, final int title, final int message, final int positiveLabel, final int negativeLabel, final Runnable onPositiveClick, final Runnable onNegativeClick) { AlertDialog.Builder dialog = new AlertDialog.Builder(activity); dialog.setTitle(title); dialog.setMessage(message); dialog.setCancelable (false); dialog.setPositiveButton(positiveLabel, new DialogInterface.OnClickListener () { public void onClick (DialogInterface dialog, int buttonId) { if (onPositiveClick != null) onPositiveClick.run(); } }); dialog.setNegativeButton(negativeLabel, new DialogInterface.OnClickListener () { public void onClick (DialogInterface dialog, int buttonId) { if (onNegativeClick != null) onNegativeClick.run(); } }); dialog.setIcon (android.R.drawable.ic_dialog_alert); dialog.show(); } } </code></pre> <p>To use the above method, something like this can be used:</p> <pre><code> Alert.confirm(activity, R.string.titFileExport, R.string.lblFileConfirmOverwrite, R.string.yes, R.string.no, new Runnable() { public void run() {performExport(activity, app, currentSong, saveFile);}}, null); return; </code></pre>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload