简体   繁体   中英

On Click/ On change item from a key of a listpreference

I am trying to make an action on a changed preference/click item from a listpreference's array. Here is what i am doing:

<PreferenceCategory android:title="@string/customization_settings" >

<ListPreference android:key="selected_theme"
    android:entries="@array/themes"
    android:title="@string/themes_title"
    android:summary="@string/themes_summary"
    android:entryValues="@array/themes_values" />
</PreferenceCategory>






 <string-array name="themes">
    <item name="dark">Verde</item>
    <item name="green">Viola</item>
</string-array>
<string-array name="themes_values">
    <item name="dark" translatable="false">0</item>
    <item name="green" translatable="false">1</item>
</string-array>

This is my list preference.
I need to set an action if the user choose an item of the array entries.
I don't know how to do it.
I searched a lot and not yet found an answer that give me a solution.

Please help me.

You can use below code for onClick event of listpreference

ListPreference selected_theme = (ListPreference) getPreferenceManager().findPreference("selected_theme");
selected_theme.setOnPreferenceChangeListener(new Preference.OnPreferenceChangeListener() {
        @Override
        public boolean onPreferenceChange(Preference preference, Object newValue) {
             return false;
        }
});

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM