Show a dialog that has one button - OK - Android User Interface

Android examples for User Interface:Dialog

Description

Show a dialog that has one button - OK

Demo Code


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

public class Main {
    /**//www . j a  v a  2 s. c o  m
     * Show a dialog that has one button - OK
     * @param context Context to grab string resources
     * @param titleRes String resource id to be put in the title
     * @param msgRes String resource id to be put in the message
     */
    public static void showOkDialog(Context context, int titleRes, int msgRes) {
            new AlertDialog.Builder(context)
                    .setTitle(context.getString(titleRes))
                    .setMessage(context.getString(msgRes))
                    .setNegativeButton(android.R.string.ok, (dialogInterface, i) -> dialogInterface.cancel())
                    .show();
        }
}

Related Tutorials