Build 1.0_r1(from source)

android.preference
Class ListPreference

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

public class ListPreference
extends DialogPreference

The ListPreference is a preference that displays a list of entries as a dialog.

This preference will store a string into the SharedPreferences. This string will be the value from the setEntryValues(CharSequence[]) array.


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
ListPreference(Context context)
           
ListPreference(Context context, AttributeSet attrs)
           
 
Method Summary
 int findIndexOfValue(String value)
          Returns the index of the given value (in the entry values array).
 CharSequence[] getEntries()
          The list of entries to be shown in the list in subsequent dialogs.
 CharSequence getEntry()
          Returns the entry corresponding to the current value.
 CharSequence[] getEntryValues()
          Returns the array of values to be saved for the preference.
 String getValue()
          Returns the value of the key.
protected  void onDialogClosed(boolean positiveResult)
          Called when the dialog is dismissed and should be used to save data to the SharedPreferences.
protected  Object onGetDefaultValue(TypedArray a, int index)
          Called when Preference is being inflated and the default value attribute needs to be read.
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.
protected  void onSetInitialValue(boolean restoreValue, Object defaultValue)
          Implement this to set the initial value of the Preference.
 void setEntries(CharSequence[] entries)
          Sets the human-readable entries to be shown in the list.
 void setEntries(int entriesResId)
           
 void setEntryValues(CharSequence[] entryValues)
          The array to find the value to save for a preference when an entry from entries is selected.
 void setEntryValues(int entryValuesResId)
           
 void setValue(String value)
          Sets the value of the key.
 void setValueIndex(int index)
          Sets the value to the given index from the entry values.
 
Methods inherited from class android.preference.DialogPreference
getDialogIcon, getDialogLayoutResource, getDialogMessage, getDialogTitle, getNegativeButtonText, getPositiveButtonText, onActivityDestroy, onBindDialogView, onClick, onClick, onCreateDialogView, onDismiss, setDialogIcon, setDialogIcon, setDialogLayoutResource, setDialogMessage, setDialogMessage, setDialogTitle, setDialogTitle, setNegativeButtonText, setNegativeButtonText, setPositiveButtonText, setPositiveButtonText, showDialog
 
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, onPrepareForRemoval, 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

ListPreference

public ListPreference(Context context,
                      AttributeSet attrs)

ListPreference

public ListPreference(Context context)
Method Detail

setEntries

public void setEntries(CharSequence[] entries)
Sets the human-readable entries to be shown in the list. This will be shown in subsequent dialogs.

Each entry must have a corresponding index in setEntryValues(CharSequence[]).

Parameters:
entries - The entries.
See Also:
setEntryValues(CharSequence[])

setEntries

public void setEntries(int entriesResId)
Parameters:
entriesResId - The entries array as a resource.
See Also:
setEntries(CharSequence[])

getEntries

public CharSequence[] getEntries()
The list of entries to be shown in the list in subsequent dialogs.

Returns:
The list as an array.

setEntryValues

public void setEntryValues(CharSequence[] entryValues)
The array to find the value to save for a preference when an entry from entries is selected. If a user clicks on the second item in entries, the second item in this array will be saved to the preference.

Parameters:
entryValues - The array to be used as values to save for the preference.

setEntryValues

public void setEntryValues(int entryValuesResId)
Parameters:
entryValuesResId - The entry values array as a resource.
See Also:
setEntryValues(CharSequence[])

getEntryValues

public CharSequence[] getEntryValues()
Returns the array of values to be saved for the preference.

Returns:
The array of values.

setValue

public void setValue(String value)
Sets the value of the key. This should be one of the entries in getEntryValues().

Parameters:
value - The value to set for the key.

setValueIndex

public void setValueIndex(int index)
Sets the value to the given index from the entry values.

Parameters:
index - The index of the value to set.

getValue

public String getValue()
Returns the value of the key. This should be one of the entries in getEntryValues().

Returns:
The value of the key.

getEntry

public CharSequence getEntry()
Returns the entry corresponding to the current value.

Returns:
The entry corresponding to the current value, or null.

findIndexOfValue

public int findIndexOfValue(String value)
Returns the index of the given value (in the entry values array).

Parameters:
value - The value whose index should be returned.
Returns:
The index of the value, or -1 if not found.

onPrepareDialogBuilder

protected void onPrepareDialogBuilder(AlertDialog.Builder builder)
Description copied from class: DialogPreference
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().

Overrides:
onPrepareDialogBuilder in class DialogPreference

onDialogClosed

protected void onDialogClosed(boolean positiveResult)
Description copied from class: DialogPreference
Called when the dialog is dismissed and should be used to save data to the SharedPreferences.

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

onGetDefaultValue

protected Object onGetDefaultValue(TypedArray a,
                                   int index)
Description copied from class: Preference
Called when Preference is being inflated and the default value attribute needs to be read. Since different preference types have different value types, the subclass should get and return the default value which will be its value type.

For example, if the value type is String, the body of the method would proxy to TypedArray.getString(int).

Overrides:
onGetDefaultValue in class Preference
Parameters:
a - The set of attributes.
index - The index of the default value attribute.
Returns:
The default value of this preference type.

onSetInitialValue

protected void onSetInitialValue(boolean restoreValue,
                                 Object defaultValue)
Description copied from class: Preference
Implement this to set the initial value of the Preference. If the restoreValue flag is true, you should restore the value from the shared preferences. If false, you should set (and possibly store to shared preferences if Preference.shouldPersist()) to defaultValue.

This may not always be called. One example is if it should not persist but there is no default value given.

Overrides:
onSetInitialValue in class Preference
Parameters:
restoreValue - Whether to restore the persisted value (true), or use the given default value (false).
defaultValue - The default value. Only use if restoreValue is false.

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 DialogPreference
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 DialogPreference
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