AlertDialog.Builder

Alert 警觉地
AlertDialog对话框
Builder建设者
displayed 显示
as the content作为内容
notified 通知,报告
via 通过
supplied 提供
chaining 链接
arguments 争论
arguments supplied提供参数
extra 额外的
processing 处理

创建对话框步骤:
1、创建对话框对象
    AlertDialog.Builder builder = new AlertDialog.Builder(this);
2、设置标题
    builder.setTitle("设置标题");
3、创建内容项目
    String[] items = { "项目一:选择本地照片", "项目二:拍照" };//创建项目
4、设置底部确定或者取消按钮
    builder.setNegativeButton("取消", null);//设置底部按钮
5、设置项目监听
源码解释:
/*    Set a list of items to be displayed in the dialog as the content, you will be             notified of the selected item via the supplied listener.
    设置项目清单作为内容显示在对话框中,你将为被选择的项目提供监听器。
    Parameters: items  listener
    Returns:  This Builder object to allow for chaining of calls to set methods
    返回值:这个建设者对象将允许通过set方法连接

Creates a AlertDialog with the arguments supplied to this builder. It does not Dialog.show() the dialog. This allows the user to do any extra processing before displaying the dialog. Use show() if you don't have any other processing to do and want this to be created and displayed.

创建一个以建设者提供参数的AlertDialog。它不使用Dialog.show()的方法显示对话框。它允许使用者做一些额外的处理,在显示对话框之前。如果你不进行一些其他的处理或者想创建并显示它,使用show()方法。
*/

    builder.setItems(items, new DialogInterface.OnClickListener(){
        public void onClick(DialogInterface dialog, int which){
            //点击按键后。因为items有两个项目,所以which就只能选择0或者1,
            //即选择项目一,或者项目二
        }
        });
6、创建并显示
    builder.create().show();//创建并显示
  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值