Resources for Android Why does Java think the string is integer?

I get the following warning for each of my XML preferences, and I understand that java considers the default values ​​that I gave are integers and it expects a string. But how can I put a letter string? I can live with a warning, since I know that it is harmless, but if there is an easy way to fix it, I will.

05-16 16:28:03.210: I/ActivityManager(68): Starting activity: Intent { cmp=com.delta.app/.Preferences }
05-16 16:28:03.750: W/Resources(1869): Converting to string: TypedValue{t=0x10/d=0x1388 a=-1}
05-16 16:28:03.870: W/Resources(1869): Converting to string: TypedValue{t=0x10/d=0x64 a=-1}
05-16 16:28:03.901: W/Resources(1869): Converting to string: TypedValue{t=0x10/d=0xa a=-1}
05-16 16:28:03.970: W/Resources(1869): Converting to string: TypedValue{t=0x10/d=0x0 a=-1}
05-16 16:28:03.970: W/Resources(1869): Converting to string: TypedValue{t=0x10/d=0x2 a=-1}

Here is the XML:

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

<EditTextPreference
    android:defaultValue="5000"
    android:key="@string/MAX_MESSAGES"
    android:summary="@string/MAX_MESSAGES_desc"
    android:title="@string/MAX_MESSAGES_title" />

<EditTextPreference
    android:defaultValue="100"
    android:key="@string/VIEW_MAX_ROWS"
    android:summary="@string/VIEW_MAX_ROWS_desc"
    android:title="@string/VIEW_MAX_ROWS_title" />

<EditTextPreference
    android:defaultValue="10"
    android:key="@string/VIEW_EDGE_ROWS"
    android:summary="@string/VIEW_EDGE_ROWS_desc"
    android:title="@string/VIEW_EDGE_ROWS_title" />

<ListPreference
    android:defaultValue="0"
    android:entries="@array/level_list"
    android:entryValues="@array/level_values"
    android:key="@string/INITIAL_ORG"
    android:summary="@string/INITIAL_ORG_desc"
    android:title="@string/INITIAL_ORG_title" />

<ListPreference
    android:defaultValue="2"
    android:entries="@array/view_list"
    android:entryValues="@array/view_values"
    android:key="@string/INITIAL_VIEW"
    android:summary="@string/INITIAL_VIEW_desc"
    android:title="@string/INITIAL_VIEW_title" />

<CheckBoxPreference
    android:defaultValue="true"
    android:key="@string/AUTOSCROLL"
    android:summary="@string/AUTOSCROLL_desc"
    android:title="@string/AUTOSCROLL_title" />

<CheckBoxPreference
    android:defaultValue="true"
    android:key="@string/SEND_THEN_EXIT"
    android:summary="@string/SEND_THEN_EXIT_desc"
    android:title="@string/SEND_THEN_EXIT_title" />

<Preference
    android:key="@string/DEFAULT_PREFS"
    android:summary="@string/DEFAULT_PREFS_desc"
    android:title="@string/DEFAULT_PREFS_title" />

</PreferenceScreen>
+5
source share
3 answers

Add this line to string.xml

<string name="five_thousand">5000</string>

ans set it by default. You can do this for other defaults ...

<EditTextPreference
    android:defaultValue="@string/five_thousand"
    android:key="@string/MAX_MESSAGES"
    android:summary="@string/MAX_MESSAGES_desc"
    android:title="@string/MAX_MESSAGES_title" />
+4
source

Double quoting each defaultValue saved me from warnings for me, but it created other problems:

<EditTextPreference
    android:defaultValue="'5000'"
    android:key="@string/MAX_MESSAGES"
    android:summary="@string/MAX_MESSAGES_desc"
    android:title="@string/MAX_MESSAGES_title" />

Value XML, , java.

Android, "5000" 5000, .

, , , .

+2

, :

<EditTextPreference
    android:defaultValue="5000 "

() , : Integer.valueOf(prefer.getstring(...). trim())

-1

All Articles