Android AlertDialog Create showAlert(Context context, int titleId, String message)

Here you can find the source of showAlert(Context context, int titleId, String message)

Description

Show Alert Dialog

License

Apache License

Parameter

Parameter Description
context a parameter
titleId a parameter
messageId a parameter

Declaration

public static void showAlert(Context context, int titleId,
        String message) 

Method Source Code

//package com.java2s;
/*//  w  ww.  j av  a  2 s  .  c o  m
 * Copyright (C) 2011 wordpress.org
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

import android.app.AlertDialog;
import android.app.Dialog;
import android.content.Context;
import android.content.DialogInterface;

public class Main {
    /**
     * Show Alert Dialog
     * @param context
     * @param titleId
     * @param messageId
     */
    public static void showAlert(Context context, int titleId, int messageId) {
        Dialog dlg = new AlertDialog.Builder(context)
                .setIcon(android.R.drawable.ic_dialog_alert)
                .setTitle(titleId)
                .setPositiveButton(android.R.string.ok, null)
                .setMessage(messageId).create();

        dlg.show();
    }

    /**
     * Show Alert Dialog
     * @param context
     * @param titleId
     * @param messageId
     */
    public static void showAlert(Context context, int titleId,
            String message) {
        Dialog dlg = new AlertDialog.Builder(context)
                .setIcon(android.R.drawable.ic_dialog_alert)
                .setTitle(titleId)
                .setPositiveButton(android.R.string.ok, null)
                .setMessage(message).create();

        dlg.show();
    }

    /**
     * Show Alert Dialog
     * @param context
     * @param titleId
     * @param messageId
     * @param positiveButtontxt
     * @param positiveListener
     * @param negativeButtontxt
     * @param negativeListener
     */
    public static void showAlert(Context context, int titleId,
            int messageId, CharSequence positiveButtontxt,
            DialogInterface.OnClickListener positiveListener,
            CharSequence negativeButtontxt,
            DialogInterface.OnClickListener negativeListener) {
        Dialog dlg = new AlertDialog.Builder(context)
                //.setIcon(android.R.drawable.ic_dialog_alert)
                .setTitle(titleId)
                .setPositiveButton(positiveButtontxt, positiveListener)
                .setNegativeButton(negativeButtontxt, negativeListener)
                .setMessage(messageId).setCancelable(false).create();

        dlg.show();
    }

    /**
     * Show Alert Dialog
     * @param context
     * @param titleId
     * @param messageId
     * @param positiveButtontxt
     * @param positiveListener
     */
    public static void showAlert(Context context, int titleId,
            String message, CharSequence positiveButtontxt,
            DialogInterface.OnClickListener positiveListener) {
        Dialog dlg = new AlertDialog.Builder(context)
                .setIcon(android.R.drawable.ic_dialog_alert)
                .setTitle(titleId)
                .setPositiveButton(positiveButtontxt, positiveListener)
                .setMessage(message).setCancelable(false).create();

        dlg.show();
    }
}

Related

  1. createOpenSourceDialog( final Context context)
  2. showAlert(Activity activity, String message)
  3. showAlert(Activity activity, String title, String message)
  4. showAlert(Activity activity, int messageStringId)
  5. showAlert(Activity activity, int titleStringId, int messageStringId)
  6. showAlert(Context context, int titleId, String message, CharSequence positiveButtontxt, DialogInterface.OnClickListener positiveListener)
  7. showAlert(Context context, int titleId, int messageId)
  8. showAlert(Context context, int titleId, int messageId, CharSequence positiveButtontxt, DialogInterface.OnClickListener positiveListener, CharSequence negativeButtontxt, DialogInterface.OnClickListener negativeListener)
  9. showAlert(Context parent, String alert)