English | Site Directory

Android - An Open Handset Alliance Project

android.app
public class

android.app.Dialog

java.lang.Object
android.app.Dialog DialogInterface KeyEvent.Callback Window.Callback

Base class for Dialogs

Known Direct Subclasses

Summary

Constants inherited from interface android.content.DialogInterface

Fields

protected      Message  mCancelMessage   
protected      boolean  mCancelable   

Public Constructors

          Dialog(Context context)
Create a Dialog window that uses the default dialog frame style.
          Dialog(Context context, int theme)
Create a Dialog window that uses a custom dialog style.

Protected Constructors

          Dialog(Context context, boolean cancelable, Message cancelCallback)
          Dialog(Context context, boolean cancelable, OnCancelListener cancelListener)

Public Methods

        void  addContentView(View view, LayoutParams params)
Add an additional content view to the screen.
        void  cancel()
Cancel (i.e.
        void  dismiss()
Dismiss this dialog, removing it from the screen.
        boolean  dispatchKeyEvent(KeyEvent event)
Called to process key events.
        boolean  dispatchTouchEvent(MotionEvent ev)
Called to process touch screen events.
        boolean  dispatchTrackballEvent(MotionEvent ev)
Called to process trackball events.
        View  findViewById(int id)
Finds a view that was identified by the id attribute from the XML that was processed in onStart().
    final    Context  getContext()
Retrieve the Context this Dialog is running in.
        View  getCurrentFocus()
Call getCurrentFocus() on the Window if this Activity to return the currently focused view.
        ViewInflate  getViewInflate()
        Window  getWindow()
Retrieve the current Window for the activity.
        void  onContentChanged()
This hook is called whenever the content view of the screen changes (due to a call to setContentView().
        boolean  onCreatePanelMenu(int featureId, Menu menu)
Initialize the contents of the menu for panel 'featureId'.
        View  onCreatePanelView(int featureId)
Instantiate the view to display in the panel for 'featureId'.
        boolean  onKeyDown(int keyCode, KeyEvent event)
A key was pressed down.
        boolean  onKeyMultiple(int keyCode, int repeatCount, KeyEvent event)
Default implementation of KeyEvent.Callback.onKeyMultiple(): always returns false (doesn't handle the event).
        boolean  onKeyUp(int keyCode, KeyEvent event)
A key was released.
        boolean  onMenuItemSelected(int featureId, Item item)
Called when a panel's menu item has been selected by the user.
        void  onPanelClosed(int featureId, Menu menu)
Called when a panel is being closed.
        boolean  onPreparePanel(int featureId, View view, Menu menu)
Prepare a panel to be displayed.
        boolean  onSearchRequested()
This hook is called when the user signals the desire to start a search.
        boolean  onTouchEvent(MotionEvent event)
Called when a touch screen event was not handled by any of the views under it.
        boolean  onTrackballEvent(MotionEvent event)
Called when the trackball was moved and not handled by any of the views inside of the activity.
        void  onWindowAttributesChanged(LayoutParams params)
This is called whenever the current window attributes change.
        void  onWindowFocusChanged(boolean hasFocus)
This hook is called whenever the window focus changes.
    final    boolean  requestWindowFeature(int featureId)
Enable extended window features.
        void  setCancelListener(OnCancelListener listener)
Set a listener to be invoked when the dialog is canceled.
        void  setCancelMessage(Message msg)
Set a message to be sent when the dialog is canceled.
        void  setCancelable(boolean flag)
Sets whether this dialog is cancelable with the BACK key.
        void  setContentView(View view, LayoutParams params)
Set the screen content to an explicit view.
        void  setContentView(View view)
Set the screen content to an explicit view.
        void  setContentView(int layoutResID)
Set the screen content from a layout resource.
    final    void  setFeatureDrawable(int featureId, Drawable drawable)
Convenience for calling setFeatureDrawable(int, Drawable).
    final    void  setFeatureDrawableAlpha(int featureId, int alpha)
Convenience for calling setFeatureDrawableAlpha(int, int).
    final    void  setFeatureDrawableResource(int featureId, int resId)
Convenience for calling setFeatureDrawableResource(int, int).
    final    void  setFeatureDrawableUri(int featureId, Uri uri)
Convenience for calling setFeatureDrawableUri(int, Uri).
        void  setTitle(int titleId)
Set the title text for this dialog's window.
        void  setTitle(CharSequence title)
Set the title text for this dialog's window.
        void  show()
Start the dialog and display it on screen.
        void  takeKeyEvents(boolean get)
Request that key events come to this dialog.

Protected Methods

        void  onStart()
Called when the dialog is starting.
        void  onStop()
Called to tell you that you're stopping.
Methods inherited from class java.lang.Object
Methods inherited from interface android.content.DialogInterface
Methods inherited from interface android.view.KeyEvent.Callback
Methods inherited from interface android.view.Window.Callback

Details

Fields

protected Message mCancelMessage

protected boolean mCancelable

Public Constructors

public Dialog(Context context)

Create a Dialog window that uses the default dialog frame style.

Parameters

context The Context the Dialog is to run it. In particular, it uses the window manager and theme in this context to present its UI.

public Dialog(Context context, int theme)

Create a Dialog window that uses a custom dialog style.

Parameters

context The Context in which the Dialog should run. In particular, it uses the window manager and theme from this context to present its UI.
theme A style resource describing the theme to use for the window. See Style and Theme Resources for more information about defining and using styles. This theme is applied on top of the current theme in context. If 0, the default dialog theme will be used.

Protected Constructors

protected Dialog(Context context, boolean cancelable, Message cancelCallback)

protected Dialog(Context context, boolean cancelable, OnCancelListener cancelListener)

Public Methods

public void addContentView(View view, LayoutParams params)

Add an additional content view to the screen. Added after any existing ones in the screen -- existing views are NOT removed.

Parameters

view The desired content to display.
params Layout parameters for the view.

public void cancel()

Cancel (i.e. dismiss) the dialog.

public void dismiss()

Dismiss this dialog, removing it from the screen.

public boolean dispatchKeyEvent(KeyEvent event)

Called to process key events. You can override this to intercept all key events before they are dispatched to the window. Be sure to call this implementation for key events that should be handled normally.

Parameters

event The key event.

Returns

  • boolean Return true if this event was consumed.

public boolean dispatchTouchEvent(MotionEvent ev)

Called to process touch screen events. You can override this to intercept all touch screen events before they are dispatched to the window. Be sure to call this implementation for touch screen events that should be handled normally.

Parameters

ev The touch screen event.

Returns

  • boolean Return true if this event was consumed.

public boolean dispatchTrackballEvent(MotionEvent ev)

Called to process trackball events. You can override this to intercept all trackball events before they are dispatched to the window. Be sure to call this implementation for trackball events that should be handled normally.

Parameters

ev The trackball event.

Returns

  • boolean Return true if this event was consumed.

public View findViewById(int id)

Finds a view that was identified by the id attribute from the XML that was processed in onStart().

Parameters

id the identifier of the view to find

Returns

  • The view if found or null otherwise.

public final Context getContext()

Retrieve the Context this Dialog is running in.

Returns

  • Context The Context that was supplied to the constructor.

public View getCurrentFocus()

Call getCurrentFocus() on the Window if this Activity to return the currently focused view.

Returns

  • View The current View with focus or null.

public ViewInflate getViewInflate()

public Window getWindow()

Retrieve the current Window for the activity. This can be used to directly access parts of the Window API that are not available through Activity/Screen.

Returns

  • Window The current window, or null if the activity is not visual.

public void onContentChanged()

This hook is called whenever the content view of the screen changes (due to a call to setContentView().

public boolean onCreatePanelMenu(int featureId, Menu menu)

Initialize the contents of the menu for panel 'featureId'. This is called if onCreatePanelView() returns null, giving you a standard menu in which you can place your items. It is only called once for the panel, the first time it is shown.

You can safely hold on to menu (and any items created from it), making modifications to it as desired, until the next time onCreatePanelMenu() is called for this feature.

public View onCreatePanelView(int featureId)

Instantiate the view to display in the panel for 'featureId'. You can return null, in which case the default content (typically a menu) will be created for you.

public boolean onKeyDown(int keyCode, KeyEvent event)

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.

public boolean onKeyMultiple(int keyCode, int repeatCount, KeyEvent event)

Default implementation of KeyEvent.Callback.onKeyMultiple(): always returns false (doesn't handle the event).

public boolean onKeyUp(int keyCode, KeyEvent event)

A key was released.

public boolean onMenuItemSelected(int featureId, Item item)

Called when a panel's menu item has been selected by the user.

public void onPanelClosed(int featureId, Menu menu)

Called when a panel is being closed. If another logical subsequent panel is being opened (and this panel is being closed to make room for the subsequent panel), this method will NOT be called.

public boolean onPreparePanel(int featureId, View view, Menu menu)

Prepare a panel to be displayed. This is called right before the panel window is shown, every time it is shown.

public boolean onSearchRequested()

This hook is called when the user signals the desire to start a search.

public boolean onTouchEvent(MotionEvent event)

Called when a touch screen event was not handled by any of the views under it. This is most useful to process touch events that happen outside of your window bounds, where there is no view to receive it.

Parameters

event The touch screen event being processed.

Returns

  • Return true if you have consumed the event, false if you haven't. The default implementation always returns false.

public boolean onTrackballEvent(MotionEvent event)

Called when the trackball was moved and not handled by any of the views inside of the activity. So, for example, if the trackball moves while focus is on a button, you will receive a call here because buttons do not normally do anything with trackball events. The call here happens before trackball movements are converted to DPAD key events, which then get sent back to the view hierarchy, and will be processed at the point for things like focus navigation.

Parameters

event The trackball event being processed.

Returns

  • Return true if you have consumed the event, false if you haven't. The default implementation always returns false.

public void onWindowAttributesChanged(LayoutParams params)

This is called whenever the current window attributes change.

public void onWindowFocusChanged(boolean hasFocus)

This hook is called whenever the window focus changes.

public final boolean requestWindowFeature(int featureId)

Enable extended window features. This is a convenience for calling getWindow().requestFeature().

Parameters

featureId The desired feature as defined in Window.

Returns

  • Returns true if the requested feature is supported and now enabled.

public void setCancelListener(OnCancelListener listener)

Set a listener to be invoked when the dialog is canceled.

Parameters

listener The DialogInterface.OnCancelListener to use.

public void setCancelMessage(Message msg)

Set a message to be sent when the dialog is canceled.

Parameters

msg The msg to send when the dialog is canceled.

public void setCancelable(boolean flag)

Sets whether this dialog is cancelable with the BACK key.

public void setContentView(View view, LayoutParams params)

Set the screen content to an explicit view. This view is placed directly into the screen's view hierarchy. It can itself be a complex view hierarhcy.

Parameters

view The desired content to display.
params Layout parameters for the view.

public void setContentView(View view)

Set the screen content to an explicit view. This view is placed directly into the screen's view hierarchy. It can itself be a complex view hierarhcy.

Parameters

view The desired content to display.

public void setContentView(int layoutResID)

Set the screen content from a layout resource. The resource will be inflated, adding all top-level views to the screen.

Parameters

layoutResID Resource ID to be inflated.

public final void setFeatureDrawable(int featureId, Drawable drawable)

Convenience for calling setFeatureDrawable(int, Drawable).

public final void setFeatureDrawableAlpha(int featureId, int alpha)

Convenience for calling setFeatureDrawableAlpha(int, int).

public final void setFeatureDrawableResource(int featureId, int resId)

Convenience for calling setFeatureDrawableResource(int, int).

public final void setFeatureDrawableUri(int featureId, Uri uri)

Convenience for calling setFeatureDrawableUri(int, Uri).

public void setTitle(int titleId)

Set the title text for this dialog's window. The text is retrieved from the resources with the supplied identifier.

Parameters

titleId the title's text resource identifier

public void setTitle(CharSequence title)

Set the title text for this dialog's window.

Parameters

title The new text to display in the title.

public void show()

Start the dialog and display it on screen. The window is placed in the application layer and opaque.

public void takeKeyEvents(boolean get)

Request that key events come to this dialog. Use this if your dialog has no views with focus, but the dialog still wants a chance to process key events.

Parameters

get true if the dialog should receive key events, false otherwise

Protected Methods

protected void onStart()

Called when the dialog is starting.

protected void onStop()

Called to tell you that you're stopping.
Build m5-rc15g - 14 May 2008 12:50