简体   繁体   中英

entryValues unexpected ressource type: 'array' expected: string in Multi Select List Preference (Android)

I try to learn sth about app preferences, found some tutorials but one thing just doesn't work for me. I use this from arrays.xml file in preference.xml as entryValues and entries for MultiSelectListPreference.

    <string-array name="cities">
        <item>Item1</item>
        <item>Item2</item>
        <item>Item3</item>
        <item>Item4</item>
        <item>Item5</item>
    </string-array>
    <string-array name="cities_keys">
        <item>item1</item>
        <item>item2</item>
        <item>item3</item>
        <item>item4</item>
        <item>item5</item>
    </string-array>
</resources>

It works fine for entries, but for entryValues I get the error mentioned in the title. Tried with string or just array instead of string-array but it didn't help. Could someone tell me what should I use here?

Besides got one more question: I used < PreferenceScreen > just 2 days ago and now it's deprecated... What should I use instead of it? What is the fastest way to check it? Developer.android.com says only to "Use the AndroidX Preference Library", but without any specifics.

Thanks a lot!

As far as I can tell, the first is a bug in Android Studio; I get the same errors in my project using a ListPreference , but it compiles, runs and executes properly. (I also get an error telling me that defaultValue should be a bool which is clearly nonsense for a string-valued preference component...)

To the latter: use androidx.preference.PreferenceScreen and friends; I found I had to force Android Studio to use it by including in build.gradle 's dependencies :

implementation 'androidx.preference:preference:1.1.0'

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