Android--单选对话框
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); } }
郑重声明:本站内容如果来自互联网及其他传播媒体,其版权均属原媒体及文章作者所有。转载目的在于传递更多信息及用于网络分享,并不代表本站赞同其观点和对其真实性负责,也不构成任何其他建议。