show Dialog and set click listener - Android User Interface

Android examples for User Interface:Dialog

Description

show Dialog and set click listener

Demo Code


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

public class Main {
    public static void showDialog(Context c, String title, String contents,
            String positiveHint, DialogInterface.OnClickListener pListener,
            String neutralHint, DialogInterface.OnClickListener nlListener,
            String negativeHint, DialogInterface.OnClickListener nListener) {

        Builder builder = new AlertDialog.Builder(c);
        builder.setCancelable(false);//w w w  .ja  v  a2  s  .c  om
        if (title != null)
            builder.setTitle(title);
        if (contents != null)
            builder.setMessage(contents);
        if (positiveHint != null)
            builder.setPositiveButton(positiveHint, pListener);
        if (neutralHint != null)
            builder.setNeutralButton(neutralHint, nlListener);
        if (negativeHint != null)
            builder.setNegativeButton(negativeHint, nListener);
        builder.show();
    }

    public static void showDialog(Context c, String title,
            String positiveHint, DialogInterface.OnClickListener pListener,
            String negativeHint, DialogInterface.OnClickListener nListener) {
        showDialog(c, title, null, positiveHint, pListener, null, null,
                negativeHint, nListener);
    }

    public static void showDialog(Context c, String title,
            String positiveHint, DialogInterface.OnClickListener pListener) {
        showDialog(c, title, null, positiveHint, pListener, null, null,
                null, null);
    }
}

Related Tutorials