Chinaunix首页 | 论坛 | 博客
  • 博客访问: 2025694
  • 博文数量: 413
  • 博客积分: 10926
  • 博客等级: 上将
  • 技术积分: 3862
  • 用 户 组: 普通用户
  • 注册时间: 2006-01-09 18:14
文章分类

全部博文(413)

文章存档

2015年(5)

2014年(1)

2013年(5)

2012年(6)

2011年(138)

2010年(85)

2009年(42)

2008年(46)

2007年(26)

2006年(59)

分类: LINUX

2010-05-31 16:08:33

http://developer.android.com/guide/topics/ui/dialogs.html

  1. Dialog Categories
    • Dialog
    • AlertDialog
      • Add lists
      • Add checkbox
      • Add radio button
    • ProgressDialog
    • DatePickerDialog
    • TimePickerDialog
    • Floating Activity
    • Customize Dialog
  2. Floating Activity
    • Add

         
                           

      to the floating activity in AndroidManifest.xml
    • Create dialog
      • Activity as dialog
      • Create a system dialog(such as AlertDialog, DatePickerDialog etc)
        public void onCreate(xx)
        {
            super.onCreate(xxx);
            setVisible(false);

            showDialog(xxx);
        }

        public Dialog createDialog(xxx)
        {
            ProgressDialog dialog = new ProgressDialog (this);
            dialog.setTitle(xxx);
            dialog.setMessage(xxx);
            return dialog;
        }
    • Floating dialog
      Intent intent = new intent();
      intent.setAction(xxx);
      intent.addCagetory(xxx);
      intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_MULTIPLE_TASK | Intent.FLAG_EXCLUDE_FROM_RECENTS);
      or
      intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_MULTIPLE_TASK | Intent.FLAG_ACTIVITY_NO_HISTORY);
      startActivity(intent);
    • xxx
  3. AlertDialog
    • Create AlertDialog
      Dialog dialog = new AlertDialog.Builder(context).setMessage(xxx).setTitle(xxx)
    • Customize AlertDialog
      LayoutInflater inflater = (LayoutInflater)context.getSystemServiceContext.LAYOUT_INFLATER_SERVICE);
      View view = inflater.inflate(R.layout.xxx, null);
      AlertDialog.Builder(context).setView(view);
    • Issue
      1. [Q]: When Alert dialog is shown, press Search key, dialog will dismiss, and application ui will be hidded, when you launch application from History or Program list, it can not be launched again uless reboot device, or kill application and then launch it again.
        [A]: The solution is to register key listener to block Search key event when to create dialog with AlertDialog.Builder, i.e.
        new AlertDialog.Builder(context).setOnKeyListener(new DialogInterface.OnKeyListener(
        {
            public boolean onKey(DialogInterface dialog, int keyCode, KeyEvent event)
            {
                if (keyCode == KeyEvent.KEYCODE_SEARCH)
                {
                    return true;
                }
                else
                {
                    return false;
                }
            }
        });
    • Android custom Dialog
      (From: http://blog.androgames.net/10/custom-android-dialog/)
      • Specify title from resource or String
      • Specify content from resource, String or custom layout
      • Set positive and negative buttons and associated listeners
    • xxx
  4. Remove dialog
    A dialog will not be destroyed when if is closed, it is keept to be used in the future, when you call showDialog to show that dialog again, the dialog is shown without to create a new one, if you want to the dialog to be destroyed when it is closed, just to invoke removeDialog(). But if you want to update contents of the dialog, just override onPrepareDialog and do something here.
  5. FAQ
    1. You are unable to show the same dialog with Activity.showDialog in its lisenter function, such as OnCanceListener\OnDismissListener\OnShowListener
    2. If you show a dialog, and then start an Activity immediately, the alert can't be shown sometimes.
    3. How to show dialog
      There are 2 ways:
      1. Invoke showDialog in Activity, and then override onCreateDialog, sometimes, you need to override onPrepareDialog also.
      2. New dialog, then call Dialog.show();
    4. Prevent alert dialog from being dismissed once button is clicked
      dialog.setButton(ProgressDialog.BUTTON_NEGATIVE,
      getString(R.string.cancel), new DialogInterface.OnClickListener() {
              @Override
              public void onClick(DialogInterface dialog, int which) {
              }
      });

      dialog.show();
      final Button cancelButton =
      dialog.getButton(DialogInterface.BUTTON_NEGATIVE);
      cancelButton.setOnClickListener(new View.OnClickListener() {
              @Override
              public void onClick(View v) {
                      // handle the click
              }
      });

      Its important to only call getButton() after show() has been called,
      or it will return null.
    5. xxx
  6. ...
阅读(1121) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~