首页 > 学院 > 开发设计 > 正文

安卓DialogHelper弹出框

2019-11-06 09:41:03
字体:
来源:转载
供稿:网友
public class DialogHelper {    /***     * 获取一个dialog对象,进行相关操作     *     * @param context     * @return     */    public static AlertDialog.Builder getDialog(Context context) {        AlertDialog.Builder builder = new AlertDialog.Builder(context);        return builder;    }    /***     * 获取一个进度对话框(耗时操作使用)     *     * @param context     * @param message     * @return     */    public static PRogressDialog getWaitDialog(Context context, String message) {        ProgressDialog waitDialog = new ProgressDialog(context);        if (!TextUtils.isEmpty(message)) {            waitDialog.setMessage(message);        }        return waitDialog;    }    public static AlertDialog.Builder getMessageDialog(Context context, String message, DialogInterface.OnClickListener onClickListener) {        AlertDialog.Builder builder = getDialog(context);        builder.setMessage(message);        builder.setPositiveButton("确定", onClickListener);        return builder;    }    /**     * 获取一个信息对话框     *     * @param context     * @param message     * @return     */    public static AlertDialog.Builder getMessageDialog(Context context, String message) {        return getMessageDialog(context, message, null);    }    public static AlertDialog.Builder getSelectDialog(Context context, String title, String[] arrays, DialogInterface.OnClickListener onClickListener) {        AlertDialog.Builder builder = getDialog(context);        builder.setItems(arrays, onClickListener);        if (!TextUtils.isEmpty(title)) {            builder.setTitle(title);        }        builder.setPositiveButton("取消", null);        return builder;    }    /**     * 选择对话框     *     * @param context     * @param arrays     * @param onClickListener     * @return     */    public static AlertDialog.Builder getSelectDialog(Context context, String[] arrays, DialogInterface.OnClickListener onClickListener) {        return getSelectDialog(context, "", arrays, onClickListener);    }    /**     * 可设置内容、确定监听对话框     *     * @param context     * @param message     * @param onClickListener     * @return     */    public static AlertDialog.Builder getConfirmDialog(Context context, String message, DialogInterface.OnClickListener onClickListener) {        AlertDialog.Builder builder = getDialog(context);        builder.setMessage(Html.fromHtml(message));        builder.setPositiveButton("确定", onClickListener);        builder.setNegativeButton("取消", null);        return builder;    }    /**     * 可设置内容、两个按钮监听对话框     *     * @param context     * @param message     * @param onOkClickListener     * @param onCancleClickListener     * @return     */    public static AlertDialog.Builder getConfirmDialog(Context context, String message, DialogInterface.OnClickListener onOkClickListener, DialogInterface.OnClickListener onCancleClickListener) {        AlertDialog.Builder builder = getDialog(context);        builder.setMessage(message);        builder.setPositiveButton("确定", onOkClickListener);        builder.setNegativeButton("取消", onCancleClickListener);        return builder;    }    /**     * 可设置标题、内容、按钮文字,监听的对话框     *     * @param context     * @param title     * @param message     * @param okString     * @param cancleString     * @param onOkClickListener     * @param onCancleClickListener     * @return     */    public static AlertDialog.Builder getConfirmDialog(Context context,                                                       String title,                                                       String message,                                                       String okString,                                                       String cancleString,                                                       DialogInterface.OnClickListener onOkClickListener,                                                       DialogInterface.OnClickListener onCancleClickListener) {        AlertDialog.Builder builder = getDialog(context);        if (!TextUtils.isEmpty(title)) {            builder.setTitle(title);        }        builder.setMessage(message);        builder.setPositiveButton(okString, onOkClickListener);        builder.setNegativeButton(cancleString, onCancleClickListener);        return builder;    }    /**     * 创建可自定义对话框内容和按钮文字的对话框     *     * @param context     * @param message               对话框内容     * @param okString              确定按钮文字     * @param cancleString          取消按钮文字     * @param onOkClickListener     确定监听     * @param onCancleClickListener 取消监听     * @return     */    public static AlertDialog.Builder getConfirmDialog(Context context,                                                       String message,                                                       String okString,                                                       String cancleString,                                                       DialogInterface.OnClickListener onOkClickListener,                                                       DialogInterface.OnClickListener onCancleClickListener) {        return getConfirmDialog(context, "", message, okString, cancleString, onOkClickListener, onCancleClickListener);    }    public static AlertDialog.Builder getSingleChoiceDialog(Context context, String title, String[] arrays, int selectIndex, DialogInterface.OnClickListener onClickListener) {        AlertDialog.Builder builder = getDialog(context);        builder.setSingleChoiceItems(arrays, selectIndex, onClickListener);        if (!TextUtils.isEmpty(title)) {            builder.setTitle(title);        }        builder.setNegativeButton("取消", null);        return builder;    }    /**     * 单选对话框     *     * @param context     * @param arrays          可供选择的数据     * @param selectIndex     默认选中的索引     * @param onClickListener     * @return     */    public static AlertDialog.Builder getSingleChoiceDialog(Context context, String[] arrays, int selectIndex, DialogInterface.OnClickListener onClickListener) {        return getSingleChoiceDialog(context, "", arrays, selectIndex, onClickListener);    }}
发表评论 共有条评论
用户名: 密码:
验证码: 匿名发表