Main.java Source code

Java tutorial

Introduction

Here is the source code for Main.java

Source

//package com.java2s;
import android.app.Activity;
import android.app.AlertDialog;

import android.content.Context;
import android.content.DialogInterface;
import android.content.DialogInterface.OnClickListener;

public class Main {

    public static void displayAlert4SingleChoice(final Context context, String title, boolean cancelable,
            String[] selectNames, final DialogInterface.OnClickListener onClickListener) {
        if (null == context || !(context instanceof Activity)) {
            return;
        }
        final Activity activity = (Activity) context;

        AlertDialog accountDlg = new AlertDialog.Builder(activity).setTitle(title).setCancelable(cancelable)
                .setSingleChoiceItems(selectNames, -1, new OnClickListener() {
                    @Override
                    public void onClick(DialogInterface dialog, int which) {
                        if (null != onClickListener) {
                            onClickListener.onClick(dialog, which);
                        }

                        if (!activity.isFinishing()) {
                            dialog.dismiss();
                        }
                    }
                }).create();

        if (!activity.isFinishing()) {
            accountDlg.show();
        }
    }
}