首页 > 代码库 > Android--单选对话框
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); } }
声明:以上内容来自用户投稿及互联网公开渠道收集整理发布,本网站不拥有所有权,未作人工编辑处理,也不承担相关法律责任,若内容有误或涉及侵权可进行投诉: 投诉/举报 工作人员会在5个工作日内联系你,一经查实,本站将立刻删除涉嫌侵权内容。