Values inside items in string-array xml - android

Is something like this possible??
<?xml version="1.0" encoding="utf-8"?>
<resources>
<string-array name="planets_array">
<item value=My >Mercury</item>
<item value=Vs >Venus</item>
<item value=EA >Earth</item>
<item value=Ms >Mars</item>
</string-array>
</resources>
the listView will show the planets but when the user selects Mars
the value I get will be Ms.

No, there is no such direct way to use string array in android app resources. One of my suggestion is separate the label and value to two different string arrays, then use these string arrays in your code.
<string-array name="planet_label">
<item>Mercury</item>
<item>Venus</item>
<item>Earth</item>
<item>Mars</item>
</string-array>
<string-array name="planet_values">
<item>My</item>
<item>Vs</item>
<item>Ea</item>
<item>Ms</item>
</string-array>

Related

Error parsing XML: junk after document element - Building an Icon Pack

I´m currently creating an free Material Design Icon Pack following [this][1] tutorial (I don´t have much experience in coding) in Eclipse. After I added some of my Icons to the applifter.xml and declared them in the iconpack.xml I get this Error when I´m trying to build it:
[2015-02-26 16:10:35 - Materialism] C:\Users\...\workspace\Materialism\res\values\iconpack.xml:10: error: Error parsing XML: junk after document element
[2015-02-26 16:10:35 - Materialism]
[2015-02-26 16:10:35 - Materialism] C:\Users\...\workspace\Materialism\res\xml\appfilter.xml:12: error: Error parsing XML: junk after document element
[2015-02-26 16:10:35 - Materialism]
[2015-02-26 16:12:30 - Materialism] Error in an XML file: aborting build.
It says "the markup in the document following the root document must be well formed"
This is my applifter.xml:
<?xml version="1.0" encoding="UTF-8"?>
<resources>
<iconback img1="iconback" />
<iconmask img1="iconmask" />
<iconupon img1="iconupon" />
<scale factor="1.1" />
<!-- Browser -->
<item component="ComponentInfo{com.android.browser/com.android.browser.BrowserActivity}" drawable="com_android_browser_browseractivity" />
<item component="ComponentInfo{com.google.android.browser/com.android.browser.BrowserActivity}" drawable="com_android_browser_browseractivity" />
</resources>
<item component="ComponentInfo{com.djit.bassboostforandroidpro/com.djit.bassboost.MainActivity}" drawable="bassbooster"
<item component="ComponentInfo{com.devhd.feedly/com.devhd.feedly.Main}" drawable="feedly"
<item component="ComponentInfo{com.rhapsody.napster/com.rhapsodycore.SplashScreen}" drawable="napster"
<item component="ComponentInfo{com.netflix.mediaclient/com.netflix.mediaclient.UIWebViewActivity}" drawable="netflix"
<item component="ComponentInfo{com.android.stk/com.android.stk.StkMenuActivity}" drawable="simtoolkit"
<item component="ComponentInfo{com.snapchat.android/com.snapchat.android.LandingPageActivity}" drawable="snapchat"
<item component="ComponentInfo{com.rarlab.rar/com.rarlab.rar.MainActivity}" drawable="rar"
<item component="ComponentInfo{com.keramidas.TitaniumBackup/com.keramidas.TitaniumBackup.MainActivity}" drawable="titaniumbackup"
And the iconpack.xml:
<?xml version="1.0" encoding="utf-8"?>
<resources>
<string-array name="icon_pack" translatable="false">
<item>com_android_browser_browseractivity</item>
</string-array>
</resources>
<string-array name="icon_pack" translatable="false">
<item>bassbooster</item>
</string-array>
<string-array name="icon_pack" translatable="false">
<item>feedly</item>
</string-array>
<string-array name="icon_pack" translatable="false">
<item>napster</item>
</string-array>
<string-array name="icon_pack" translatable="false">
<item>netflix</item>
</string-array>
<string-array name="icon_pack" translatable="false">
<item>rar</item>
</string-array>
<string-array name="icon_pack" translatable="false">
<item>simtoolkit</item>
</string-array>
How can I resolve this?
Thank in advance :-)
XML files have a strictly defined structure which you must follow. In this case everything must be between the
<resources>
.... everything must be here ....
</resources>
tags. Putting anything after the </resources> will result in the 'not well formed error'. (The <?xml version="1.0" encoding="utf-8"?> is the exception and must be first).
Also some of your
<item component="ComponentInfo{com.djit.bassboostforandroidpro/com.djit.bassboost.MainActivity}" drawable="bassbooster"
values do not end properly. There must be a /> at the end of each item - like this:
<item component="ComponentInfo{com.djit.bassboostforandroidpro/com.djit.bassboost.MainActivity}" drawable="bassbooster" />

android string-array item attributes

I have string array like this:
<resources xmlns:android="http://schemas.android.com/apk/res/android">
<string-array name="my_videos">
<item>bunny.mp4</item>
<item>bunny.m4a</item>
<item>bunny.3gp</item>
</string-array>
And in my app I have this:
String product = ((TextView) view).getText().toString();
Now I want to put some normal text like this:
<resources xmlns:android="http://schemas.android.com/apk/res/android">
<string-array name="my_videos">
<item name="bunny.mp4">Movie description 1</item>
<item name="bunny.m4a">Movie description 2</item>
<item name="bunny.3gp">Movie description 3</item>
</string-array>
Now I want to acces name attribute and not get text.
I am new to Android and do not know if this is possible.
Please help.

Creating a ListPreference options menu

I'm trying to create an option menu in my preferences but I can't get the options to display. When I select the option in the prefs menu I got an empty pop up dialog (title at the top, button at the bottom, but no options).
This is what I do:
I create an array.xml file in res/values
<?xml version="1.0" encoding="utf-8"?>
<resources>
<string-array name="listArray">
<item>3</item>
<item>5</item>
<item>7</item>
<item>10</item>
<item>15</item>
<item>20</item>
</string-array>
<string-array name="listValues">
<item>3</item>
<item>5</item>
<item>7</item>
<item>10</item>
<item>15</item>
<item>20</item>
</string-array>
and in m prefs.xml i have:
<ListPreference
android:dialogTitle="#string/prefsMaxAdAge"
android:dialogMessage="#string/prefsMaxAdAgeSummary"
android:key="itemMaxAdAge"
android:title="#string/prefsMaxAdAge"
android:summary="#string/prefsMaxAdAgeSummary"
android:entryValues="#array/listValues"
android:entries="#array/listArray">
</ListPreference>
Any help would be much appreciated! Thank you!
I finally found the solution to that problem.
The XML field DialogMsg must not be set. This makes sense after all.
Useful help was found here:
http://code.google.com/p/android/issues/detail?id=4497
ListPreferences seem to appear empty whenever they contain a dialogMessage. As to why, I would very much like to know the answer...

how to NAME a string-array using a string resource

How can I do this?
<string-array name="#string/a_string_from_resources">
Is it possible to name a string-array using a string Resource?
<?xml version="1.0" encoding="utf-8"?>
<resources>
<string-array name="#string/a_string_from_resources">
<item>first</item>
<item>second</item>
<item>third</item>
<item>fourth</item>
<item>fifth</item>
</string-array>
</resources>
<string-array name="array_name">
My guess is you cant! Because the R.java is generated from all the resources at the same time. As the xmls are meaningless before generating, resource files wont be able to gather the resources from themselves.

string array in string.xml in Android

I want to create a string array in string.xml in values folder for my android application. How to do this.. can anybody help..
<?xml version="1.0" encoding="utf-8"?>
<resources>
<string-array name="my_array">
<item>string1</item>
<item>string2</item>
<item>string3</item>
</string-array>
</resources>

Categories

Resources