Build 1.0_r1(from source)

android.preference
Class DialogPreference

java.lang.Object
  extended by android.preference.Preference
      extended by android.preference.DialogPreference
All Implemented Interfaces:
DialogInterface.OnClickListener, DialogInterface.OnDismissListener, OnDependencyChangeListener, PreferenceManager.OnActivityDestroyListener, Comparable<Preference>
Direct Known Subclasses:
EditTextPreference, ListPreference, SeekBarPreference

public abstract class DialogPreference
extends Preference
implements DialogInterface.OnClickListener, DialogInterface.OnDismissListener, PreferenceManager.OnActivityDestroyListener

The DialogPreference class is a base class for preferences that are dialog-based. These preferences will, when clicked, open a dialog showing the actual preference controls.


Nested Class Summary
 
Nested classes/interfaces inherited from class android.preference.Preference
Preference.BaseSavedState, Preference.OnPreferenceChangeInternalListener, Preference.OnPreferenceChangeListener, Preference.OnPreferenceClickListener
 
Field Summary
 
Fields inherited from class android.preference.Preference
DEFAULT_ORDER
 
Constructor Summary
DialogPreference(Context context, AttributeSet attrs)
           
DialogPreference(Context context, AttributeSet attrs, int defStyle)
           
 
Method Summary
 Drawable getDialogIcon()
          Returns the icon to be shown on subsequent dialogs.
 int getDialogLayoutResource()
          Returns the layout resource that is used as the content View for subsequent dialogs.
 CharSequence getDialogMessage()
          Returns the message to be shown on subsequent dialogs.
 CharSequence getDialogTitle()
          Returns the title to be shown on subsequent dialogs.
 CharSequence getNegativeButtonText()
          Returns the text of the negative button to be shown on subsequent dialogs.
 CharSequence getPositiveButtonText()
          Returns the text of the positive button to be shown on subsequent dialogs.
 void onActivityDestroy()
          See Activity's onDestroy.
protected  void onBindDialogView(View view)
          Binds views in the content View of the dialog to data.
protected  void onClick()
          Processes a click on the preference.
 void onClick(DialogInterface dialog, int which)
          This method will be invoked when a button in the dialog is clicked.
protected  View onCreateDialogView()
          Creates the content view for the dialog (if a custom content view is required).
protected  void onDialogClosed(boolean positiveResult)
          Called when the dialog is dismissed and should be used to save data to the SharedPreferences.
 void onDismiss(DialogInterface dialog)
          This method will be invoked when the dialog is dismissed.
protected  void onPrepareDialogBuilder(AlertDialog.Builder builder)
          Prepares the dialog builder to be shown when the preference is clicked.
protected  void onRestoreInstanceState(Parcelable state)
          Hook allowing a preference to re-apply a representation of its internal state that had previously been generated by Preference.onSaveInstanceState().
protected  Parcelable onSaveInstanceState()
          Hook allowing a preference to generate a representation of its internal state that can later be used to create a new instance with that same state.
 void setDialogIcon(Drawable dialogIcon)
          Sets the icon of the dialog.
 void setDialogIcon(int dialogIconRes)
          Sets the icon (resource ID) of the dialog.
 void setDialogLayoutResource(int dialogLayoutResId)
          Sets the layout resource that is inflated as the View to be shown as the content View of subsequent dialogs.
 void setDialogMessage(CharSequence dialogMessage)
          Sets the message of the dialog.
 void setDialogMessage(int dialogMessageResId)
           
 void setDialogTitle(CharSequence dialogTitle)
          Sets the title of the dialog.
 void setDialogTitle(int dialogTitleResId)
           
 void setNegativeButtonText(CharSequence negativeButtonText)
          Sets the text of the negative button of the dialog.
 void setNegativeButtonText(int negativeButtonTextResId)
           
 void setPositiveButtonText(CharSequence positiveButtonText)
          Sets the text of the positive button of the dialog.
 void setPositiveButtonText(int positiveButtonTextResId)
           
protected  void showDialog(Bundle state)
          Shows the dialog associated with this Preference.
 
Methods inherited from class android.preference.Preference
callChangeListener, compareTo, dispatchRestoreInstanceState, dispatchSaveInstanceState, findPreferenceInHierarchy, getContext, getDependency, getEditor, getFilterableStringBuilder, getId, getIntent, getKey, getLayoutResource, getOnPreferenceChangeListener, getOnPreferenceClickListener, getOrder, getPersistedBoolean, getPersistedFloat, getPersistedInt, getPersistedLong, getPersistedString, getPreferenceManager, getSharedPreferences, getShouldDisableView, getSummary, getTitle, getView, getWidgetLayoutResource, hasKey, hasSpecifiedLayout, isEnabled, isPersistent, isSelectable, notifyChanged, notifyDependencyChange, notifyHierarchyChanged, onAttachedToActivity, onAttachedToHierarchy, onBindView, onCreateView, onDependencyChanged, onGetDefaultValue, onPrepareForRemoval, onSetInitialValue, performClick, persistBoolean, persistFloat, persistInt, persistLong, persistString, requireKey, restoreHierarchyState, saveHierarchyState, setDefaultValue, setDependency, setEnabled, setIntent, setKey, setLayoutResource, setOnPreferenceChangeInternalListener, setOnPreferenceChangeListener, setOnPreferenceClickListener, setOrder, setPersistent, setSelectable, setShouldDisableView, setSummary, setSummary, setTitle, setTitle, setWidgetLayoutResource, shouldCommit, shouldDisableDependents, shouldPersist, toString
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

DialogPreference

public DialogPreference(Context context,
                        AttributeSet attrs,
                        int defStyle)

DialogPreference

public DialogPreference(Context context,
                        AttributeSet attrs)
Method Detail

setDialogTitle

public void setDialogTitle(CharSequence dialogTitle)
Sets the title of the dialog. This will be shown on subsequent dialogs.

Parameters:
dialogTitle - The title.

setDialogTitle

public void setDialogTitle(int dialogTitleResId)
Parameters:
dialogTitleResId - The dialog title as a resource.
See Also:
setDialogTitle(CharSequence)

getDialogTitle

public CharSequence getDialogTitle()
Returns the title to be shown on subsequent dialogs.

Returns:
The title.

setDialogMessage

public void setDialogMessage(CharSequence dialogMessage)
Sets the message of the dialog. This will be shown on subsequent dialogs.

This message forms the content View of the dialog and conflicts with list-based dialogs, for example. If setting a custom View on a dialog via setDialogLayoutResource(int), include a text View with ID R.id.message and it will be populated with this message.

Parameters:
dialogMessage - The message.

setDialogMessage

public void setDialogMessage(int dialogMessageResId)
Parameters:
dialogMessageResId - The dialog message as a resource.
See Also:
setDialogMessage(CharSequence)

getDialogMessage

public CharSequence getDialogMessage()
Returns the message to be shown on subsequent dialogs.

Returns:
The message.

setDialogIcon

public void setDialogIcon(Drawable dialogIcon)
Sets the icon of the dialog. This will be shown on subsequent dialogs.

Parameters:
dialogIcon - The icon, as a Drawable.

setDialogIcon

public void setDialogIcon(int dialogIconRes)
Sets the icon (resource ID) of the dialog. This will be shown on subsequent dialogs.

Parameters:
dialogIconRes - The icon, as a resource ID.

getDialogIcon

public Drawable getDialogIcon()
Returns the icon to be shown on subsequent dialogs.

Returns:
The icon, as a Drawable.

setPositiveButtonText

public void setPositiveButtonText(CharSequence positiveButtonText)
Sets the text of the positive button of the dialog. This will be shown on subsequent dialogs.

Parameters:
positiveButtonText - The text of the positive button.

setPositiveButtonText

public void setPositiveButtonText(int positiveButtonTextResId)
Parameters:
positiveButtonTextResId - The positive button text as a resource.
See Also:
setPositiveButtonText(CharSequence)

getPositiveButtonText

public CharSequence getPositiveButtonText()
Returns the text of the positive button to be shown on subsequent dialogs.

Returns:
The text of the positive button.

setNegativeButtonText

public void setNegativeButtonText(CharSequence negativeButtonText)
Sets the text of the negative button of the dialog. This will be shown on subsequent dialogs.

Parameters:
negativeButtonText - The text of the negative button.

setNegativeButtonText

public void setNegativeButtonText(int negativeButtonTextResId)
Parameters:
negativeButtonTextResId - The negative button text as a resource.
See Also:
setNegativeButtonText(CharSequence)

getNegativeButtonText

public CharSequence getNegativeButtonText()
Returns the text of the negative button to be shown on subsequent dialogs.

Returns:
The text of the negative button.

setDialogLayoutResource

public void setDialogLayoutResource(int dialogLayoutResId)
Sets the layout resource that is inflated as the View to be shown as the content View of subsequent dialogs.

Parameters:
dialogLayoutResId - The layout resource ID to be inflated.
See Also:
setDialogMessage(CharSequence)

getDialogLayoutResource

public int getDialogLayoutResource()
Returns the layout resource that is used as the content View for subsequent dialogs.

Returns:
The layout resource.

onPrepareDialogBuilder

protected void onPrepareDialogBuilder(AlertDialog.Builder builder)
Prepares the dialog builder to be shown when the preference is clicked. Use this to set custom properties on the dialog.

Do not AlertDialog.Builder#create() or AlertDialog.Builder#show().


onClick

protected void onClick()
Description copied from class: Preference
Processes a click on the preference. This includes saving the value to the SharedPreferences. However, the overridden method should call Preference.callChangeListener(Object) to make sure the client wants to update the preference's state with the new value.

Overrides:
onClick in class Preference

showDialog

protected void showDialog(Bundle state)
Shows the dialog associated with this Preference. This is normally initiated automatically on clicking on the preference. Call this method if you need to show the dialog on some other event.

Parameters:
state - Optional instance state to restore on the dialog

onCreateDialogView

protected View onCreateDialogView()
Creates the content view for the dialog (if a custom content view is required). By default, it inflates the dialog layout resource if it is set.

Returns:
The content View for the dialog.
See Also:
Preference.setLayoutResource(int)

onBindDialogView

protected void onBindDialogView(View view)
Binds views in the content View of the dialog to data.

Make sure to call through to the superclass implementation.

Parameters:
view - The content View of the dialog, if it is custom.

onClick

public void onClick(DialogInterface dialog,
                    int which)
Description copied from interface: DialogInterface.OnClickListener
This method will be invoked when a button in the dialog is clicked.

Specified by:
onClick in interface DialogInterface.OnClickListener
Parameters:
dialog - The dialog that received the click.
which - The button that was clicked, i.e. BUTTON1 or BUTTON2 or the position of the item clicked.

onDismiss

public void onDismiss(DialogInterface dialog)
Description copied from interface: DialogInterface.OnDismissListener
This method will be invoked when the dialog is dismissed.

Specified by:
onDismiss in interface DialogInterface.OnDismissListener
Parameters:
dialog - The dialog that was dismissed will be passed into the method.

onDialogClosed

protected void onDialogClosed(boolean positiveResult)
Called when the dialog is dismissed and should be used to save data to the SharedPreferences.

Parameters:
positiveResult - Whether the positive button was clicked (true), or the negative button was clicked or the dialog was canceled (false).

onActivityDestroy

public void onActivityDestroy()
See Activity's onDestroy.

Specified by:
onActivityDestroy in interface PreferenceManager.OnActivityDestroyListener

onSaveInstanceState

protected Parcelable onSaveInstanceState()
Description copied from class: Preference
Hook allowing a preference to generate a representation of its internal state that can later be used to create a new instance with that same state. This state should only contain information that is not persistent or can be reconstructed later.

Overrides:
onSaveInstanceState in class Preference
Returns:
Returns a Parcelable object containing the preference's current dynamic state, or null if there is nothing interesting to save. The default implementation returns null.
See Also:
Preference.onRestoreInstanceState(android.os.Parcelable), Preference.saveHierarchyState(android.os.Bundle), Preference.dispatchSaveInstanceState(android.os.Bundle)

onRestoreInstanceState

protected void onRestoreInstanceState(Parcelable state)
Description copied from class: Preference
Hook allowing a preference to re-apply a representation of its internal state that had previously been generated by Preference.onSaveInstanceState(). This function will never be called with a null icicle.

Overrides:
onRestoreInstanceState in class Preference
Parameters:
state - The frozen state that had previously been returned by Preference.onSaveInstanceState().
See Also:
Preference.onSaveInstanceState(), Preference.restoreHierarchyState(android.os.Bundle), Preference.dispatchRestoreInstanceState(android.os.Bundle)

Build 1.0_r1(from source)

Please submit a feedback, bug or feature