package com.example.util; import android.app.AlertDialog; import android.app.AlertDialog.Builder; import android.app.Dialog; import android.content.Context; import android.content.DialogInterface; import android.content.DialogInterface.OnDismissListener; public class SelectSupplyDialog { public static boolean isShow = false; public static Builder builder; public static Dialog dialog; public SelectSupplyDialog(){ } // 弹窗结果回调函数 public static abstract class ResultCallBack { public abstract void callback(int pos); } public static void showMyDialog(Context context, String title, String[] strArr, final ResultCallBack callback){ if(builder != null){ builder = null; } builder = new AlertDialog.Builder(context); builder.setIcon(android.R.drawable.ic_dialog_info); builder.setTitle(title); builder.setSingleChoiceItems(strArr, 0, new DialogInterface.OnClickListener() { public void onClick(DialogInterface builder, int which) { isShow = false; builder.dismiss(); callback.callback(which); } } ); dialog = builder.show(); isShow = true; builder.setCancelable(true); } public static void closeDialog(){ if(dialog != null && isShow == true){ dialog.dismiss(); } } } /** * 扫描人选择 * @param v */ public void supply(View v){ SelectSupplyDialog.showMyDialog(mContext, "请选择供应商", strScanMan, new ResultCallBack() { @Override public void callback(int pos) { } }); } private String[] strScanMan = {"张飞","刘备","关羽"};
时间: 2024-10-11 11:42:49