码迷,mamicode.com
首页 > 移动开发 > 详细

Android--单选对话框

时间:2014-05-06 00:07:01      阅读:307      评论:0      收藏:0      [点我收藏+]

标签:android   style   blog   class   code   java   

bubuko.com,布布扣
import android.app.AlertDialog;
import android.content.Context;
import android.content.DialogInterface;
import android.text.TextUtils;
import android.widget.TextView;

/**
 * 单选对话框
 * 
 * @author Administrator
 * 
 */
public class DialogSelector {
    /**
     * 单选对话框
     * 
     * @param context
     * @param sTitle
     * @param choices
     * @param tv
     */
    public static void showSelectDlg(Context context, String sTitle,
            final String[] choices, final TextView tv) {
        final AlertDialog.Builder builder = new AlertDialog.Builder(context);
        if (sTitle != null) {
            builder.setTitle(sTitle);
        }
        builder.setSingleChoiceItems(choices, 0,
                new DialogInterface.OnClickListener() {
                    public void onClick(DialogInterface dialog, int which) {
                        dialog.dismiss();
                        if (tv != null)
                            tv.setText(choices[which]);
                    }
                });
        builder.create().show();
    }

    /**
     * 单选对话框
     * 
     * @param context
     * @param sTitle
     * @param choices
     * @param tv
     */
    public static void showSelectDlg(Context context, String sTitle,
            final String[] choices,
            final OnItemSelectListener onItemSelectListener) {
        final AlertDialog.Builder builder = new AlertDialog.Builder(context);
        if (!TextUtils.isEmpty(sTitle)) {
            builder.setTitle(sTitle);
        }
        builder.setSingleChoiceItems(choices, 0,
                new DialogInterface.OnClickListener() {
                    public void onClick(DialogInterface dialog, int which) {
                        dialog.dismiss();
                        if (onItemSelectListener != null) {
                            onItemSelectListener.onItemSelected(which);
                        }
                    }
                });
        builder.create().show();
    }

    public interface OnItemSelectListener {
        public void onItemSelected(int position);
    }
}
bubuko.com,布布扣

 

Android--单选对话框,布布扣,bubuko.com

Android--单选对话框

标签:android   style   blog   class   code   java   

原文地址:http://www.cnblogs.com/crane13/p/3704445.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!