Chinaunix

标题: AlertDialog [打印本页]

作者: fenfenxu1989    时间: 2011-12-20 09:44
标题: AlertDialog
  1. 1、AlertDialog创建流程:
      1.      先是创建AlertDialog.Builder对象,然后设置此对象,最后调用create()方法创建AlertDialog
  2. 2、AlertDialog.Builder的方法:
之上这四个,同一个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();
                  





欢迎光临 Chinaunix (http://bbs.chinaunix.net/) Powered by Discuz! X3.2