免费注册 查看新帖 |

Chinaunix

  平台 论坛 博客 文库
最近访问板块 发新帖
查看: 805 | 回复: 0
打印 上一主题 下一主题

AlertDialog [复制链接]

论坛徽章:
0
跳转到指定楼层
1 [收藏(0)] [报告]
发表于 2011-12-20 09:44 |只看该作者 |倒序浏览
  1. 1、AlertDialog创建流程:
      1.      先是创建AlertDialog.Builder对象,然后设置此对象,最后调用create()方法创建AlertDialog
  2. 2、AlertDialog.Builder的方法:
  • setIcon
  • setTitle
  • setPositiveButton
  • setNeutralButton
  • setNegativeButton
  • setMessage
  • setItems
  • setSingleChoiceItems
  • setMultiChoiceItems
之上这四个,同一个Builder只能调用一次,不可以共存
  1. public AlertDialog create ()

    Creates a AlertDialog with the arguments supplied to this builder. It does not 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.

  2. 创建完AlertDialog后是不显示的,要想显示需再调用show()方法。

  3. 3、举例:
      1. new AlertDialog.Builder(AlertDialogSamples.this)
      2.                 .setIcon(R.drawable.ic_popup_reminder)
      3.                 .setTitle(R.string.alert_dialog_multi_choice)
      4.                 .setMultiChoiceItems(R.array.select_dialog_items3,
      5.                         new boolean[]{false, true, false, true, false, false, false},
      6.                         new DialogInterface.OnMultiChoiceClickListener() {
      7.                             public void onClick(DialogInterface dialog, int whichButton,
      8.                                     boolean isChecked) {

      9.                                 /* User clicked on a check box do some stuff */
      10.                             }
      11.                         })
      12.                 .setPositiveButton(R.string.alert_dialog_ok,
      13.                         new DialogInterface.OnClickListener() {
      14.                     public void onClick(DialogInterface dialog, int whichButton) {

      15.                         /* User clicked Yes so do some stuff */
      16.                     }
      17.                 })
      18.                 .setNegativeButton(R.string.alert_dialog_cancel,
      19.                         new DialogInterface.OnClickListener() {
      20.                     public void onClick(DialogInterface dialog, int whichButton) {

      21.                         /* User clicked No so do some stuff */
      22.                     }
      23.                 })
      24.                .create();
                  
您需要登录后才可以回帖 登录 | 注册

本版积分规则 发表回复

  

北京盛拓优讯信息技术有限公司. 版权所有 京ICP备16024965号-6 北京市公安局海淀分局网监中心备案编号:11010802020122 niuxiaotong@pcpop.com 17352615567
未成年举报专区
中国互联网协会会员  联系我们:huangweiwei@itpub.net
感谢所有关心和支持过ChinaUnix的朋友们 转载本站内容请注明原作者名及出处

清除 Cookies - ChinaUnix - Archiver - WAP - TOP