AlertDialog.Builder

  • Post author:
  • Post category:其他


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();//创建并显示



版权声明:本文为u014084233原创文章,遵循 CC 4.0 BY-SA 版权协议,转载请附上原文出处链接和本声明。