Domanda

I am new in android development and developing pref.xml (resource type prefrence) using eclipe software. Here is my pref.xml code

<?xml version="1.0" encoding="utf-8"?>
<PreferenceScreen xmlns:android="http://schemas.android.com/apk/res/android" >

<EditTextPreference
 android:title="EditText"
 android:key = "name"
 android:summary="Enter Your name"
 ></EditTextPreference>

 <CheckBoxPreference
 android:title="CheckBox"
 android:defaultValue="true"
 android:key="checkBox"
 android:summary="check this box"
 ></CheckBoxPreference>

 <ListPreference
 android:title="List"
 android:key="list"
 android:summary="This Is A List To Choose From"
 android:entries="array/list"
 ></ListPreference>

and i got this error :

error: Error: String types not allowed (at 'entries' with value 'array/list')

Please help me.. how do i handle this error ?

È stato utile?

Soluzione

Find file name strings.xml in res\value folder in your package explorer... add following line in this file

<string-array name="list"></string-array>

Your Final file look like

<?xml version="1.0" encoding="utf-8"?>
<resources>

<string name="app_name">Muzafar Khan</string>
<string name="action_settings">Settings</string>
<string name="hello_world">Hello world!</string>

<string-array name="list"></string-array>

Now save your project... and enjoy :)

Altri suggerimenti

Change

android:entries="array/list" 

to

android:entries="@array/list"

I am assuming you are trying to load the entries from the array resource file, correct? If so, you need to do "@array/list" instead. All of the resources (string, id, etc) must be prefixed with @ in the XML.

This one worked for me

android:entries="@+array/list"

hope it helps :)

android:entries="@array/list"

gives an error, you have to use

android:entries="@+array/list

You need to create resource type 'arrays' in the 'res' folder where the array elements will be defined after declaring the array type in the pref_general.xml file. In the arrays.xml file you can define as

       <string-array name="**array name**">
            <item>@string/**array element 1**</item>
            <item>@string/**array element 2**</item>
        </string-array>



So in your pref general file you will actually define array as 

android:entryValues="@array/array name"

So in your string file you define the array elements as strings in normal way

Cheers 

go to values package create a new xml file for ex- array.xml then

<resources>
<string-array name="list"></string-array>

set the string-array and change

android:entries="array/list"

to

android:entries="@array/list" 

for refering the file :

Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top