public class MultiSelectListPreference 
   extends DialogPreference 
| java.lang.Object | |||
| ↳ | android.preference.Preference | ||
| ↳ | android.preference.DialogPreference | ||
| ↳ | android.preference.MultiSelectListPreference | ||
一个 Preference ,显示作为对话框的条目列表。
此首选项将一组字符串存储到SharedPreferences中。 该组将包含来自setEntryValues(CharSequence[])阵列的一个或多个值。
XML attributes |  
      |
|---|---|
android:entries |  
       The human-readable array to present as a list. | 
android:entryValues |  
       The array to find the value to save for a preference when an entry from entries is selected. | 
Inherited XML attributes |  
      |
|---|---|
  android.preference.DialogPreference  
         |  
      |
  android.preference.Preference  
         |  
      |
Inherited constants |  
      
|---|
  android.preference.Preference  
         |  
      
Public constructors |  
      |
|---|---|
  MultiSelectListPreference(Context context, AttributeSet attrs, int defStyleAttr, int defStyleRes)   |  
      |
  MultiSelectListPreference(Context context, AttributeSet attrs, int defStyleAttr)   |  
      |
  MultiSelectListPreference(Context context, AttributeSet attrs)   |  
      |
  MultiSelectListPreference(Context context)   |  
      |
Public methods |  
      |
|---|---|
 int  |  
         findIndexOfValue(String value)  返回给定值的索引(在条目值数组中)。  |  
      
 CharSequence[]  |  
         getEntries()  要在后续对话框中显示在列表中的条目列表。  |  
      
 CharSequence[]  |  
         getEntryValues()  返回要为首选项保存的值数组。  |  
      
 Set<String>  |  
         getValues()  检索密钥的当前值。  |  
      
 void  |  
         setEntries(CharSequence[] entries)  设置人类可读条目以显示在列表中。  |  
      
 void  |  
         setEntries(int entriesResId)   |  
      
 void  |  
         setEntryValues(int entryValuesResId)   |  
      
 void  |  
         setEntryValues(CharSequence[] entryValues)  选择条目中的条目时查找要保存的首选项的值的数组。  |  
      
 void  |  
         setValues(Set<String> values)  设置密钥的值。  |  
      
Protected methods |  
      |
|---|---|
 void  |  
         onDialogClosed(boolean positiveResult)  当对话框被解除时应该被调用,并且应该被用来保存数据到   |  
      
 Object  |  
         onGetDefaultValue(TypedArray a, int index)  当首选项被夸大并且需要读取默认值属性时调用。  |  
      
 void  |  
         onPrepareDialogBuilder(AlertDialog.Builder builder)  准备在单击首选项时显示对话框构建器。  |  
      
 Parcelable  |  
         onSaveInstanceState()  钩子允许首选项生成其内部状态的表示,稍后可用于创建具有相同状态的新实例。  |  
      
 void  |  
         onSetInitialValue(boolean restoreValue, Object defaultValue)  执行此操作来设置首选项的初始值。  |  
      
Inherited methods |  
      |
|---|---|
  android.preference.DialogPreference  
         |  
      |
  android.preference.Preference  
         |  
      |
  java.lang.Object  
         |  
      |
  android.content.DialogInterface.OnClickListener  
         |  
      |
  android.content.DialogInterface.OnDismissListener  
         |  
      |
  android.preference.PreferenceManager.OnActivityDestroyListener  
         |  
      |
  java.lang.Comparable  
         |  
      |
将人类可读的数组作为列表呈现。 每个条目在entryValues中都必须有相应的索引。
必须是另一个资源的引用,其形式为“ @[+][package:]type:name ”,或者其形式为“一个主题属性 ?[package:][type:]name ”。
这对应于全局属性资源符号 entries 。
选择条目中的条目时查找要保存的首选项的值的数组。 如果用户单击条目中的第二项,则此数组中的第二项将保存到首选项。
必须是另一个资源的引用,其形式为“ @[+][package:]type:name ”,或者其形式为“一个主题属性 ?[package:][type:]name ”。
这对应于全局属性资源符号 entryValues 。
MultiSelectListPreference (Context context, AttributeSet attrs, int defStyleAttr, int defStyleRes)
| Parameters | |
|---|---|
context |  
         Context 
          |  
       
attrs |  
         AttributeSet 
          |  
       
defStyleAttr |  
         int 
          |  
       
defStyleRes |  
         int 
          |  
       
MultiSelectListPreference (Context context, AttributeSet attrs, int defStyleAttr)
| Parameters | |
|---|---|
context |  
         Context 
          |  
       
attrs |  
         AttributeSet 
          |  
       
defStyleAttr |  
         int 
          |  
       
MultiSelectListPreference (Context context, AttributeSet attrs)
| Parameters | |
|---|---|
context |  
         Context 
          |  
       
attrs |  
         AttributeSet 
          |  
       
MultiSelectListPreference (Context context)
| Parameters | |
|---|---|
context |  
         Context 
          |  
       
int findIndexOfValue (String value)
返回给定值的索引(在条目值数组中)。
| Parameters | |
|---|---|
value |  
         String: The value whose index should be returned. |  
       
| Returns | |
|---|---|
int |  
        The index of the value, or -1 if not found. | 
CharSequence[] getEntries ()
要在后续对话框中显示在列表中的条目列表。
| Returns | |
|---|---|
CharSequence[] |  
        The list as an array. | 
CharSequence[] getEntryValues ()
返回要为首选项保存的值数组。
| Returns | |
|---|---|
CharSequence[] |  
        The array of values. | 
void setEntries (CharSequence[] entries)
设置人类可读条目以显示在列表中。 这将在随后的对话框中显示。
每个条目必须在 setEntryValues(CharSequence[])有相应的索引。
| Parameters | |
|---|---|
entries |  
         CharSequence: The entries. |  
       
void setEntries (int entriesResId)
| Parameters | |
|---|---|
entriesResId |  
         int: The entries array as a resource.  |  
       
也可以看看:
void setEntryValues (int entryValuesResId)
| Parameters | |
|---|---|
entryValuesResId |  
         int: The entry values array as a resource.  |  
       
void setEntryValues (CharSequence[] entryValues)
选择条目中的条目时查找要保存的首选项的值的数组。 如果用户单击条目中的第二项,则此数组中的第二项将保存到首选项。
| Parameters | |
|---|---|
entryValues |  
         CharSequence: The array to be used as values to save for the preference.  |  
       
void setValues (Set<String> values)
设置密钥的值。 这应该包含getEntryValues()中的条目。
| Parameters | |
|---|---|
values |  
         Set: The values to set for the key.  |  
       
void onDialogClosed (boolean positiveResult)
当对话框被解除并且应该用于将数据保存到 SharedPreferences 。
| Parameters | |
|---|---|
positiveResult |  
         boolean: Whether the positive button was clicked (true), or the negative button was clicked or the dialog was canceled (false).  |  
       
Object onGetDefaultValue (TypedArray a, int index)
当首选项被夸大并且需要读取默认值属性时调用。 由于不同的首选项类型具有不同的值类型,因此子类应获取并返回默认值,该默认值将是其值类型。
例如,如果值类型为String,则方法的主体将代理为 getString(int) 。
| Parameters | |
|---|---|
a |  
         TypedArray: The set of attributes. |  
       
index |  
         int: The index of the default value attribute. |  
       
| Returns | |
|---|---|
Object |  
        The default value of this preference type. | 
void onPrepareDialogBuilder (AlertDialog.Builder builder)
准备在单击首选项时显示对话框构建器。 使用它在对话框上设置自定义属性。
| Parameters | |
|---|---|
builder |  
         AlertDialog.Builder 
          |  
       
Parcelable onSaveInstanceState ()
钩子允许首选项生成其内部状态的表示,稍后可用于创建具有相同状态的新实例。 这个状态应该只包含不持久的或者稍后可以重建的信息。
| Returns | |
|---|---|
Parcelable |  
        A Parcelable object containing the current dynamic state of this Preference, or null if there is nothing interesting to save. The default implementation returns null. | 
void onSetInitialValue (boolean restoreValue, 
                Object defaultValue) 
     执行此操作来设置首选项的初始值。
如果restorePersistedValue为true,则应从SharedPreferences恢复首选项值。 如果restorePersistedValue为false,则应将Preference值设置为给定的defaultValue(并且如果shouldPersist()为true,则可能shouldPersist()其存储到SharedPreferences中)。
这可能并不总是被称为。 一个例子是,如果它不应该坚持,但没有给出默认值。
| Parameters | |
|---|---|
restoreValue |  
         boolean: True to restore the persisted value; false to use the given defaultValue. |  
       
defaultValue |  
         Object: The default value for this Preference. Only use this if restorePersistedValue is false.  |