Java Code Examples for android.support.v7.preference.ListPreference#findIndexOfValue()

The following examples show how to use android.support.v7.preference.ListPreference#findIndexOfValue() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: SettingsFragment.java    From android-dev-challenge with Apache License 2.0 6 votes vote down vote up
private void setPreferenceSummary(Preference preference, Object value) {
    String stringValue = value.toString();
    String key = preference.getKey();

    if (preference instanceof ListPreference) {
        /* For list preferences, look up the correct display value in */
        /* the preference's 'entries' list (since they have separate labels/values). */
        ListPreference listPreference = (ListPreference) preference;
        int prefIndex = listPreference.findIndexOfValue(stringValue);
        if (prefIndex >= 0) {
            preference.setSummary(listPreference.getEntries()[prefIndex]);
        }
    } else {
        // For other preferences, set the summary to the value's simple string representation.
        preference.setSummary(stringValue);
    }
}
 
Example 2
Source File: SettingsFragment.java    From android-dev-challenge with Apache License 2.0 6 votes vote down vote up
private void setPreferenceSummary(Preference preference, Object value) {
    String stringValue = value.toString();

    if (preference instanceof ListPreference) {
        // For list preferences, look up the correct display value in
        // the preference's 'entries' list (since they have separate labels/values).
        ListPreference listPreference = (ListPreference) preference;
        int prefIndex = listPreference.findIndexOfValue(stringValue);
        if (prefIndex >= 0) {
            preference.setSummary(listPreference.getEntries()[prefIndex]);
        }
    } else {
        // For other preferences, set the summary to the value's simple string representation.
        preference.setSummary(stringValue);
    }
}
 
Example 3
Source File: SettingsFragment.java    From android-dev-challenge with Apache License 2.0 6 votes vote down vote up
private void setPreferenceSummary(Preference preference, Object value) {
    String stringValue = value.toString();

    if (preference instanceof ListPreference) {
        // For list preferences, look up the correct display value in
        // the preference's 'entries' list (since they have separate labels/values).
        ListPreference listPreference = (ListPreference) preference;
        int prefIndex = listPreference.findIndexOfValue(stringValue);
        if (prefIndex >= 0) {
            preference.setSummary(listPreference.getEntries()[prefIndex]);
        }
    } else {
        // For other preferences, set the summary to the value's simple string representation.
        preference.setSummary(stringValue);
    }
}
 
Example 4
Source File: SettingsFragment.java    From android-dev-challenge with Apache License 2.0 6 votes vote down vote up
private void setPreferenceSummary(Preference preference, Object value) {
    String stringValue = value.toString();

    if (preference instanceof ListPreference) {
        // For list preferences, look up the correct display value in
        // the preference's 'entries' list (since they have separate labels/values).
        ListPreference listPreference = (ListPreference) preference;
        int prefIndex = listPreference.findIndexOfValue(stringValue);
        if (prefIndex >= 0) {
            preference.setSummary(listPreference.getEntries()[prefIndex]);
        }
    } else {
        // For other preferences, set the summary to the value's simple string representation.
        preference.setSummary(stringValue);
    }
}
 
Example 5
Source File: SettingsFragment.java    From android-dev-challenge with Apache License 2.0 6 votes vote down vote up
private void setPreferenceSummary(Preference preference, Object value) {
    String stringValue = value.toString();

    if (preference instanceof ListPreference) {
        // For list preferences, look up the correct display value in
        // the preference's 'entries' list (since they have separate labels/values).
        ListPreference listPreference = (ListPreference) preference;
        int prefIndex = listPreference.findIndexOfValue(stringValue);
        if (prefIndex >= 0) {
            preference.setSummary(listPreference.getEntries()[prefIndex]);
        }
    } else {
        // For other preferences, set the summary to the value's simple string representation.
        preference.setSummary(stringValue);
    }
}
 
Example 6
Source File: SettingsFragment.java    From android-dev-challenge with Apache License 2.0 6 votes vote down vote up
private void setPreferenceSummary(Preference preference, Object value) {
    String stringValue = value.toString();

    if (preference instanceof ListPreference) {
        // For list preferences, look up the correct display value in
        // the preference's 'entries' list (since they have separate labels/values).
        ListPreference listPreference = (ListPreference) preference;
        int prefIndex = listPreference.findIndexOfValue(stringValue);
        if (prefIndex >= 0) {
            preference.setSummary(listPreference.getEntries()[prefIndex]);
        }
    } else {
        // For other preferences, set the summary to the value's simple string representation.
        preference.setSummary(stringValue);
    }
}
 
Example 7
Source File: SettingsFragment.java    From android-dev-challenge with Apache License 2.0 6 votes vote down vote up
private void setPreferenceSummary(Preference preference, Object value) {
    String stringValue = value.toString();

    if (preference instanceof ListPreference) {
        // For list preferences, look up the correct display value in
        // the preference's 'entries' list (since they have separate labels/values).
        ListPreference listPreference = (ListPreference) preference;
        int prefIndex = listPreference.findIndexOfValue(stringValue);
        if (prefIndex >= 0) {
            preference.setSummary(listPreference.getEntries()[prefIndex]);
        }
    } else {
        // For other preferences, set the summary to the value's simple string representation.
        preference.setSummary(stringValue);
    }
}
 
Example 8
Source File: SettingsFragment.java    From android-dev-challenge with Apache License 2.0 6 votes vote down vote up
private void setPreferenceSummary(Preference preference, Object value) {
    String stringValue = value.toString();

    if (preference instanceof ListPreference) {
        // For list preferences, look up the correct display value in
        // the preference's 'entries' list (since they have separate labels/values).
        ListPreference listPreference = (ListPreference) preference;
        int prefIndex = listPreference.findIndexOfValue(stringValue);
        if (prefIndex >= 0) {
            preference.setSummary(listPreference.getEntries()[prefIndex]);
        }
    } else {
        // For other preferences, set the summary to the value's simple string representation.
        preference.setSummary(stringValue);
    }
}
 
Example 9
Source File: SettingsFragment.java    From android-dev-challenge with Apache License 2.0 6 votes vote down vote up
private void setPreferenceSummary(Preference preference, Object value) {
    String stringValue = value.toString();

    if (preference instanceof ListPreference) {
        // For list preferences, look up the correct display value in
        // the preference's 'entries' list (since they have separate labels/values).
        ListPreference listPreference = (ListPreference) preference;
        int prefIndex = listPreference.findIndexOfValue(stringValue);
        if (prefIndex >= 0) {
            preference.setSummary(listPreference.getEntries()[prefIndex]);
        }
    } else {
        // For other preferences, set the summary to the value's simple string representation.
        preference.setSummary(stringValue);
    }
}
 
Example 10
Source File: SettingsFragment.java    From android-dev-challenge with Apache License 2.0 6 votes vote down vote up
private void setPreferenceSummary(Preference preference, Object value) {
    String stringValue = value.toString();

    if (preference instanceof ListPreference) {
        // For list preferences, look up the correct display value in
        // the preference's 'entries' list (since they have separate labels/values).
        ListPreference listPreference = (ListPreference) preference;
        int prefIndex = listPreference.findIndexOfValue(stringValue);
        if (prefIndex >= 0) {
            preference.setSummary(listPreference.getEntries()[prefIndex]);
        }
    } else {
        // For other preferences, set the summary to the value's simple string representation.
        preference.setSummary(stringValue);
    }
}
 
Example 11
Source File: SettingsFragment.java    From android-dev-challenge with Apache License 2.0 6 votes vote down vote up
private void setPreferenceSummary(Preference preference, Object value) {
    String stringValue = value.toString();

    if (preference instanceof ListPreference) {
        // For list preferences, look up the correct display value in
        // the preference's 'entries' list (since they have separate labels/values).
        ListPreference listPreference = (ListPreference) preference;
        int prefIndex = listPreference.findIndexOfValue(stringValue);
        if (prefIndex >= 0) {
            preference.setSummary(listPreference.getEntries()[prefIndex]);
        }
    } else {
        // For other preferences, set the summary to the value's simple string representation.
        preference.setSummary(stringValue);
    }
}
 
Example 12
Source File: SettingsFragment.java    From android-dev-challenge with Apache License 2.0 6 votes vote down vote up
private void setPreferenceSummary(Preference preference, Object value) {
    String stringValue = value.toString();

    if (preference instanceof ListPreference) {
        // For list preferences, look up the correct display value in
        // the preference's 'entries' list (since they have separate labels/values).
        ListPreference listPreference = (ListPreference) preference;
        int prefIndex = listPreference.findIndexOfValue(stringValue);
        if (prefIndex >= 0) {
            preference.setSummary(listPreference.getEntries()[prefIndex]);
        }
    } else {
        // For other preferences, set the summary to the value's simple string representation.
        preference.setSummary(stringValue);
    }
}
 
Example 13
Source File: SettingsFragment.java    From android-dev-challenge with Apache License 2.0 6 votes vote down vote up
private void setPreferenceSummary(Preference preference, Object value) {
    String stringValue = value.toString();

    if (preference instanceof ListPreference) {
        // For list preferences, look up the correct display value in
        // the preference's 'entries' list (since they have separate labels/values).
        ListPreference listPreference = (ListPreference) preference;
        int prefIndex = listPreference.findIndexOfValue(stringValue);
        if (prefIndex >= 0) {
            preference.setSummary(listPreference.getEntries()[prefIndex]);
        }
    } else {
        // For other preferences, set the summary to the value's simple string representation.
        preference.setSummary(stringValue);
    }
}
 
Example 14
Source File: SettingsFragment.java    From android-dev-challenge with Apache License 2.0 6 votes vote down vote up
private void setPreferenceSummary(Preference preference, Object value) {
    String stringValue = value.toString();

    if (preference instanceof ListPreference) {
        // For list preferences, look up the correct display value in
        // the preference's 'entries' list (since they have separate labels/values).
        ListPreference listPreference = (ListPreference) preference;
        int prefIndex = listPreference.findIndexOfValue(stringValue);
        if (prefIndex >= 0) {
            preference.setSummary(listPreference.getEntries()[prefIndex]);
        }
    } else {
        // For other preferences, set the summary to the value's simple string representation.
        preference.setSummary(stringValue);
    }
}
 
Example 15
Source File: PrinterDetailsFragment.java    From octoandroid with GNU General Public License v3.0 6 votes vote down vote up
@Override
public boolean onPreferenceChange(Preference preference, Object newValue) {
    String stringValue = newValue.toString();

    if (preference instanceof ListPreference) {
        // For list preferences, look up the correct display value in
        // the preference's 'entries' list (since they have separate labels/values).
        ListPreference listPreference = (ListPreference) preference;
        int prefIndex = listPreference.findIndexOfValue(stringValue);
        if (prefIndex >= 0) {
            preference.setSummary(listPreference.getEntries()[prefIndex]);
        }
    } else {
        // For other preferences, set the summary to the value's simple string representation.
        preference.setSummary(stringValue);
    }
    return true;
}
 
Example 16
Source File: SettingsActivity.java    From Orin with GNU General Public License v3.0 5 votes vote down vote up
private static void setSummary(Preference preference, @NonNull Object value) {
    String stringValue = value.toString();

    if (preference instanceof ListPreference) {
        ListPreference listPreference = (ListPreference) preference;
        int index = listPreference.findIndexOfValue(stringValue);
        preference.setSummary(
                index >= 0
                        ? listPreference.getEntries()[index]
                        : null);
    } else {
        preference.setSummary(stringValue);
    }
}
 
Example 17
Source File: SettingsFragment.java    From android-dev-challenge with Apache License 2.0 5 votes vote down vote up
private void setPreferenceSummary(Preference preference, Object value) {
    if (preference instanceof ListPreference) {
        ListPreference listPreference = (ListPreference) preference;
        int prefIndex = listPreference.findIndexOfValue(value.toString());
        if (prefIndex >= 0) {
            preference.setSummary(listPreference.getEntries()[prefIndex]);
        }
    } else {
        preference.setSummary(value.toString());
    }
}
 
Example 18
Source File: SettingsActivity.java    From RetroMusicPlayer with GNU General Public License v3.0 5 votes vote down vote up
private static void setSummary(Preference preference, @NonNull Object value) {
    String stringValue = value.toString();

    if (preference instanceof ListPreference) {
        ListPreference listPreference = (ListPreference) preference;
        int index = listPreference.findIndexOfValue(stringValue);
        preference.setSummary(index >= 0 ? listPreference.getEntries()[index] : null);
    } else {
        preference.setSummary(stringValue);
    }
}
 
Example 19
Source File: BeaconActionPageFragment.java    From beaconloc with Apache License 2.0 5 votes vote down vote up
private void setActionType(String newValue) {
    final ListPreference action_list = (ListPreference) findPreference("ba_action_list");
    if (newValue != null && !newValue.isEmpty()) {
        int index = action_list.findIndexOfValue(newValue);
        action_list.setSummary(index >= 0
                ? action_list.getEntries()[index]
                : null);
        mActionBeacon.setActionType(ActionBeacon.ActionType.fromInt(index >= 0 ? index : 0));
    } else {
        action_list.setSummary(action_list.getEntries()[0]);
        mActionBeacon.setActionType(ActionBeacon.ActionType.fromInt(0));
    }
}
 
Example 20
Source File: SettingsFragment.java    From android-dev-challenge with Apache License 2.0 5 votes vote down vote up
/**
 * Updates the summary for the preference
 *
 * @param preference The preference to be updated
 * @param value      The value that the preference was updated to
 */
private void setPreferenceSummary(Preference preference, String value) {
    // COMPLETED (3) Don't forget to add code here to properly set the summary for an EditTextPreference
    if (preference instanceof ListPreference) {
        // For list preferences, figure out the label of the selected value
        ListPreference listPreference = (ListPreference) preference;
        int prefIndex = listPreference.findIndexOfValue(value);
        if (prefIndex >= 0) {
            // Set the summary to that label
            listPreference.setSummary(listPreference.getEntries()[prefIndex]);
        }
    } else if (preference instanceof EditTextPreference) {
        preference.setSummary(value);
    }
}