Build 1.1_r1 (from source)

android.app
Class AlertDialog

java.lang.Object
  extended by android.app.Dialog
      extended by android.app.AlertDialog
All Implemented Interfaces:
DialogInterface, KeyEvent.Callback, View.OnCreateContextMenuListener, Window.Callback
Direct Known Subclasses:
DatePickerDialog, ProgressDialog, TimePickerDialog

public class AlertDialog
extends Dialog
implements DialogInterface

A subclass of Dialog that can display one, two or three buttons. If you only want to display a String in this dialog box, use the setMessage() method. If you want to display a more complex view, look up the FrameLayout called "body" and add your view to it:

 FrameLayout fl = (FrameLayout) findViewById(R.id.body);
 fl.add(myView, new LayoutParams(FILL_PARENT, WRAP_CONTENT));
 

The AlertDialog class takes care of automatically setting WindowManager.LayoutParams.FLAG_ALT_FOCUSABLE_IM for you based on whether any views in the dialog return true from View.onCheckIsTextEditor(). Generally you want this set for a Dialog without text editors, so that it will be placed on top of the current input method UI. You can modify this behavior by forcing the flag to your desired mode after calling onCreate(android.os.Bundle).


Nested Class Summary
static class AlertDialog.Builder
           
 
Nested classes/interfaces inherited from interface android.content.DialogInterface
DialogInterface.OnCancelListener, DialogInterface.OnClickListener, DialogInterface.OnDismissListener, DialogInterface.OnKeyListener, DialogInterface.OnMultiChoiceClickListener
 
Field Summary
 
Fields inherited from class android.app.Dialog
mCancelable, mContext, mDecor, mWindow, mWindowManager
 
Fields inherited from interface android.content.DialogInterface
BUTTON_NEGATIVE, BUTTON_NEUTRAL, BUTTON_POSITIVE, BUTTON1, BUTTON2, BUTTON3
 
Constructor Summary
protected AlertDialog(Context context)
           
protected AlertDialog(Context context, boolean cancelable, DialogInterface.OnCancelListener cancelListener)
           
protected AlertDialog(Context context, int theme)
           
 
Method Summary
 Button getButton(int whichButton)
          Gets one of the buttons used in the dialog.
 ListView getListView()
          Gets the list view used in the dialog.
protected  void onCreate(Bundle savedInstanceState)
          Similar to Activity.onCreate(android.os.Bundle), you should initialized your dialog in this method, including calling Dialog.setContentView(int).
 boolean onKeyDown(int keyCode, KeyEvent event)
          A key was pressed down.
 boolean onKeyUp(int keyCode, KeyEvent event)
          A key was released.
 void setButton(CharSequence text, DialogInterface.OnClickListener listener)
          Deprecated. Use setButton(int, CharSequence, android.content.DialogInterface.OnClickListener) with DialogInterface.BUTTON_POSITIVE
 void setButton(CharSequence text, Message msg)
          Deprecated. Use setButton(int, CharSequence, Message) with DialogInterface.BUTTON_POSITIVE.
 void setButton(int whichButton, CharSequence text, DialogInterface.OnClickListener listener)
          Set a listener to be invoked when the positive button of the dialog is pressed.
 void setButton(int whichButton, CharSequence text, Message msg)
          Set a message to be sent when a button is pressed.
 void setButton2(CharSequence text, DialogInterface.OnClickListener listener)
          Deprecated. Use setButton(int, CharSequence, android.content.DialogInterface.OnClickListener) with DialogInterface.BUTTON_NEGATIVE
 void setButton2(CharSequence text, Message msg)
          Deprecated. Use setButton(int, CharSequence, Message) with DialogInterface.BUTTON_NEGATIVE.
 void setButton3(CharSequence text, DialogInterface.OnClickListener listener)
          Deprecated. Use setButton(int, CharSequence, android.content.DialogInterface.OnClickListener) with DialogInterface.BUTTON_POSITIVE
 void setButton3(CharSequence text, Message msg)
          Deprecated. Use setButton(int, CharSequence, Message) with DialogInterface.BUTTON_NEUTRAL.
 void setCustomTitle(View customTitleView)
           
 void setIcon(Drawable icon)
           
 void setIcon(int resId)
          Set resId to 0 if you don't want an icon.
 void setInverseBackgroundForced(boolean forceInverseBackground)
           
 void setMessage(CharSequence message)
           
 void setTitle(CharSequence title)
          Set the title text for this dialog's window.
 void setView(View view)
          Set the view to display in that dialog.
 void setView(View view, int viewSpacingLeft, int viewSpacingTop, int viewSpacingRight, int viewSpacingBottom)
          Set the view to display in that dialog, specifying the spacing to appear around that view.
 
Methods inherited from class android.app.Dialog
addContentView, cancel, closeOptionsMenu, dismiss, dispatchKeyEvent, dispatchOnCreate, dispatchTouchEvent, dispatchTrackballEvent, findViewById, getContext, getCurrentFocus, getLayoutInflater, getOwnerActivity, getVolumeControlStream, getWindow, hide, isShowing, onContentChanged, onContextItemSelected, onContextMenuClosed, onCreateContextMenu, onCreateOptionsMenu, onCreatePanelMenu, onCreatePanelView, onKeyMultiple, onMenuItemSelected, onMenuOpened, onOptionsItemSelected, onOptionsMenuClosed, onPanelClosed, onPrepareOptionsMenu, onPreparePanel, onRestoreInstanceState, onSaveInstanceState, onSearchRequested, onStart, onStop, onTouchEvent, onTrackballEvent, onWindowAttributesChanged, onWindowFocusChanged, openContextMenu, openOptionsMenu, registerForContextMenu, requestWindowFeature, setCancelable, setCanceledOnTouchOutside, setCancelMessage, setContentView, setContentView, setContentView, setDismissMessage, setFeatureDrawable, setFeatureDrawableAlpha, setFeatureDrawableResource, setFeatureDrawableUri, setOnCancelListener, setOnDismissListener, setOnKeyListener, setOwnerActivity, setTitle, setVolumeControlStream, show, takeKeyEvents, unregisterForContextMenu
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 
Methods inherited from interface android.content.DialogInterface
cancel, dismiss
 

Constructor Detail

AlertDialog

protected AlertDialog(Context context)

AlertDialog

protected AlertDialog(Context context,
                      int theme)

AlertDialog

protected AlertDialog(Context context,
                      boolean cancelable,
                      DialogInterface.OnCancelListener cancelListener)
Method Detail

getButton

public Button getButton(int whichButton)
Gets one of the buttons used in the dialog.

If a button does not exist in the dialog, null will be returned.

Parameters:
whichButton - The identifier of the button that should be returned. For example, this can be DialogInterface.BUTTON_POSITIVE.
Returns:
The button from the dialog, or null if a button does not exist.

getListView

public ListView getListView()
Gets the list view used in the dialog.

Returns:
The ListView from the dialog.

setTitle

public void setTitle(CharSequence title)
Description copied from class: Dialog
Set the title text for this dialog's window.

Overrides:
setTitle in class Dialog
Parameters:
title - The new text to display in the title.

setCustomTitle

public void setCustomTitle(View customTitleView)
See Also:
AlertDialog.Builder.setCustomTitle(View)

setMessage

public void setMessage(CharSequence message)

setView

public void setView(View view)
Set the view to display in that dialog.


setView

public void setView(View view,
                    int viewSpacingLeft,
                    int viewSpacingTop,
                    int viewSpacingRight,
                    int viewSpacingBottom)
Set the view to display in that dialog, specifying the spacing to appear around that view.

Parameters:
view - The view to show in the content area of the dialog
viewSpacingLeft - Extra space to appear to the left of view
viewSpacingTop - Extra space to appear above view
viewSpacingRight - Extra space to appear to the right of view
viewSpacingBottom - Extra space to appear below view

setButton

public void setButton(int whichButton,
                      CharSequence text,
                      Message msg)
Set a message to be sent when a button is pressed.

Parameters:
whichButton - Which button to set the message for, can be one of DialogInterface.BUTTON_POSITIVE, DialogInterface.BUTTON_NEGATIVE, or DialogInterface.BUTTON_NEUTRAL
text - The text to display in positive button.
msg - The Message to be sent when clicked.

setButton

public void setButton(int whichButton,
                      CharSequence text,
                      DialogInterface.OnClickListener listener)
Set a listener to be invoked when the positive button of the dialog is pressed.

Parameters:
whichButton - Which button to set the listener on, can be one of DialogInterface.BUTTON_POSITIVE, DialogInterface.BUTTON_NEGATIVE, or DialogInterface.BUTTON_NEUTRAL
text - The text to display in positive button.
listener - The DialogInterface.OnClickListener to use.

setButton

@Deprecated
public void setButton(CharSequence text,
                                 Message msg)
Deprecated. Use setButton(int, CharSequence, Message) with DialogInterface.BUTTON_POSITIVE.


setButton2

@Deprecated
public void setButton2(CharSequence text,
                                  Message msg)
Deprecated. Use setButton(int, CharSequence, Message) with DialogInterface.BUTTON_NEGATIVE.


setButton3

@Deprecated
public void setButton3(CharSequence text,
                                  Message msg)
Deprecated. Use setButton(int, CharSequence, Message) with DialogInterface.BUTTON_NEUTRAL.


setButton

@Deprecated
public void setButton(CharSequence text,
                                 DialogInterface.OnClickListener listener)
Deprecated. Use setButton(int, CharSequence, android.content.DialogInterface.OnClickListener) with DialogInterface.BUTTON_POSITIVE

Set a listener to be invoked when button 1 of the dialog is pressed.

Parameters:
text - The text to display in button 1.
listener - The DialogInterface.OnClickListener to use.

setButton2

@Deprecated
public void setButton2(CharSequence text,
                                  DialogInterface.OnClickListener listener)
Deprecated. Use setButton(int, CharSequence, android.content.DialogInterface.OnClickListener) with DialogInterface.BUTTON_NEGATIVE

Set a listener to be invoked when button 2 of the dialog is pressed.

Parameters:
text - The text to display in button 2.
listener - The DialogInterface.OnClickListener to use.

setButton3

@Deprecated
public void setButton3(CharSequence text,
                                  DialogInterface.OnClickListener listener)
Deprecated. Use setButton(int, CharSequence, android.content.DialogInterface.OnClickListener) with DialogInterface.BUTTON_POSITIVE

Set a listener to be invoked when button 3 of the dialog is pressed.

Parameters:
text - The text to display in button 3.
listener - The DialogInterface.OnClickListener to use.

setIcon

public void setIcon(int resId)
Set resId to 0 if you don't want an icon.

Parameters:
resId - the resourceId of the drawable to use as the icon or 0 if you don't want an icon.

setIcon

public void setIcon(Drawable icon)

setInverseBackgroundForced

public void setInverseBackgroundForced(boolean forceInverseBackground)

onCreate

protected void onCreate(Bundle savedInstanceState)
Description copied from class: Dialog
Similar to Activity.onCreate(android.os.Bundle), you should initialized your dialog in this method, including calling Dialog.setContentView(int).

Overrides:
onCreate in class Dialog
Parameters:
savedInstanceState - If this dialog is being reinitalized after a the hosting activity was previously shut down, holds the result from the most recent call to Dialog.onSaveInstanceState(), or null if this is the first time.

onKeyDown

public boolean onKeyDown(int keyCode,
                         KeyEvent event)
Description copied from class: Dialog
A key was pressed down.

If the focused view didn't want this event, this method is called.

The default implementation handles KEYCODE_BACK to close the dialog.

Specified by:
onKeyDown in interface KeyEvent.Callback
Overrides:
onKeyDown in class Dialog
Parameters:
keyCode - The value in event.getKeyCode().
event - Description of the key event.
Returns:
If you handled the event, return true. If you want to allow the event to be handled by the next receiver, return false.
See Also:
Dialog.onKeyUp(int, android.view.KeyEvent), KeyEvent

onKeyUp

public boolean onKeyUp(int keyCode,
                       KeyEvent event)
Description copied from class: Dialog
A key was released.

Specified by:
onKeyUp in interface KeyEvent.Callback
Overrides:
onKeyUp in class Dialog
Parameters:
keyCode - The value in event.getKeyCode().
event - Description of the key event.
Returns:
If you handled the event, return true. If you want to allow the event to be handled by the next receiver, return false.
See Also:
Dialog.onKeyDown(int, android.view.KeyEvent), KeyEvent

Build 1.1_r1 (from source)

Please submit a feedback, bug or feature