Show a yes/no dialog, providing the yes listener function - Android User Interface

Android examples for User Interface:Dialog

Description

Show a yes/no dialog, providing the yes listener function

Demo Code


//package com.java2s;
import android.app.AlertDialog;
import android.content.Context;
import android.content.DialogInterface;

public class Main {
    /**// w w w.  j  a va  2s .  c o m
     * Show a yes/no dialog, providing the yes listener function
     */
    public static void showYesNoDialog(Context context, int titleRes, int msgRes, DialogInterface.OnClickListener posListener) {
            new AlertDialog.Builder(context)
                    .setTitle(context.getString(titleRes))
                    .setMessage(context.getString(msgRes))
                    .setNegativeButton(android.R.string.no, (dialogInterface, i) -> dialogInterface.cancel())
                    .setPositiveButton(android.R.string.yes, posListener)
                    .show();
        }
}

Related Tutorials