Constructors Summary |
---|
public MultiSelectListPreference(android.content.Context context, android.util.AttributeSet attrs, int defStyleAttr, int defStyleRes)
super(context, attrs, defStyleAttr, defStyleRes);
final TypedArray a = context.obtainStyledAttributes(attrs,
com.android.internal.R.styleable.MultiSelectListPreference, defStyleAttr,
defStyleRes);
mEntries = a.getTextArray(com.android.internal.R.styleable.MultiSelectListPreference_entries);
mEntryValues = a.getTextArray(com.android.internal.R.styleable.MultiSelectListPreference_entryValues);
a.recycle();
|
public MultiSelectListPreference(android.content.Context context, android.util.AttributeSet attrs, int defStyleAttr)
this(context, attrs, defStyleAttr, 0);
|
public MultiSelectListPreference(android.content.Context context, android.util.AttributeSet attrs)
this(context, attrs, com.android.internal.R.attr.dialogPreferenceStyle);
|
public MultiSelectListPreference(android.content.Context context)
this(context, null);
|
Methods Summary |
---|
public int | findIndexOfValue(java.lang.String value)Returns the index of the given value (in the entry values array).
if (value != null && mEntryValues != null) {
for (int i = mEntryValues.length - 1; i >= 0; i--) {
if (mEntryValues[i].equals(value)) {
return i;
}
}
}
return -1;
|
public java.lang.CharSequence[] | getEntries()The list of entries to be shown in the list in subsequent dialogs.
return mEntries;
|
public java.lang.CharSequence[] | getEntryValues()Returns the array of values to be saved for the preference.
return mEntryValues;
|
private boolean[] | getSelectedItems()
final CharSequence[] entries = mEntryValues;
final int entryCount = entries.length;
final Set<String> values = mValues;
boolean[] result = new boolean[entryCount];
for (int i = 0; i < entryCount; i++) {
result[i] = values.contains(entries[i].toString());
}
return result;
|
public java.util.Set | getValues()Retrieves the current value of the key.
return mValues;
|
protected void | onDialogClosed(boolean positiveResult)
super.onDialogClosed(positiveResult);
if (positiveResult && mPreferenceChanged) {
final Set<String> values = mNewValues;
if (callChangeListener(values)) {
setValues(values);
}
}
mPreferenceChanged = false;
|
protected java.lang.Object | onGetDefaultValue(android.content.res.TypedArray a, int index)
final CharSequence[] defaultValues = a.getTextArray(index);
final int valueCount = defaultValues.length;
final Set<String> result = new HashSet<String>();
for (int i = 0; i < valueCount; i++) {
result.add(defaultValues[i].toString());
}
return result;
|
protected void | onPrepareDialogBuilder(android.app.AlertDialog.Builder builder)
super.onPrepareDialogBuilder(builder);
if (mEntries == null || mEntryValues == null) {
throw new IllegalStateException(
"MultiSelectListPreference requires an entries array and " +
"an entryValues array.");
}
boolean[] checkedItems = getSelectedItems();
builder.setMultiChoiceItems(mEntries, checkedItems,
new DialogInterface.OnMultiChoiceClickListener() {
public void onClick(DialogInterface dialog, int which, boolean isChecked) {
if (isChecked) {
mPreferenceChanged |= mNewValues.add(mEntryValues[which].toString());
} else {
mPreferenceChanged |= mNewValues.remove(mEntryValues[which].toString());
}
}
});
mNewValues.clear();
mNewValues.addAll(mValues);
|
protected android.os.Parcelable | onSaveInstanceState()
final Parcelable superState = super.onSaveInstanceState();
if (isPersistent()) {
// No need to save instance state
return superState;
}
final SavedState myState = new SavedState(superState);
myState.values = getValues();
return myState;
|
protected void | onSetInitialValue(boolean restoreValue, java.lang.Object defaultValue)
setValues(restoreValue ? getPersistedStringSet(mValues) : (Set<String>) defaultValue);
|
public void | setEntries(java.lang.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
{@link #setEntryValues(CharSequence[])}.
mEntries = entries;
|
public void | setEntries(int entriesResId)
setEntries(getContext().getResources().getTextArray(entriesResId));
|
public void | setEntryValues(java.lang.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.
mEntryValues = entryValues;
|
public void | setEntryValues(int entryValuesResId)
setEntryValues(getContext().getResources().getTextArray(entryValuesResId));
|
public void | setValues(java.util.Set values)Sets the value of the key. This should contain entries in
{@link #getEntryValues()}.
mValues.clear();
mValues.addAll(values);
persistStringSet(values);
|