android string-array item attributes - android

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.

Related

reference string array res id from an array

I have the following XML
<string-array name="str_arr1">
<item>My item 1</item>
<item>My item 2</item>
<item>My item 3</item>
</string-array>
<string-array name="str_arr2">
<item>My item 4</item>
<item>My item 5</item>
<item>My item 6</item>
</string-array>
How can I reference the above strings arrays using an array.. something like below (maybe another type of array needs to be used?)
<string-array name="my_strings_arrays">
<item>R.array.str_arr1</item>
<item>R.array.str_arr2</item>
</string-array>
Basically in the code, I want to read the my_strings_arrays and then for each array , I want to grab the list of items within.
In any xml resource file we can use reference of array/string/integer/color/etc. with "#" prefix.
So, here we can use #array for getting reference of another array str_arr1 and str_arr2.
<string-array name="str_arr1">
<item>My item 1</item>
<item>My item 2</item>
<item>My item 3</item>
</string-array>
<string-array name="str_arr2">
<item>My item 4</item>
<item>My item 5</item>
<item>My item 6</item>
</string-array>
You to need change your code as below.
<string-array name="my_strings_arrays">
<item>#array/str_arr1</item>
<item>#array/str_arr2</item>
</string-array>
Your second array should be an array of string arrays, not string array of string arrays.
I think the way you would do what you need is:
<array name="my_strings_arrays">
<item>#array/str_arr1 </item>
<item>#array/str_arr2 </item>
</array>

Values inside items in string-array xml

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>

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" />

how to change the color of string array resources in android

This is my menu_items.xml whose elements are shown in a listview. They are Black coloured by default. I want them to be white. How can in change the color of these string-array items?
Below is my menu_items.xml code.
<?xml version="1.0" encoding="utf-8"?>
<resources>
<string-array name="menu_items" >
<item >Demo Mode</item>
<item >Inbox</item>
<item >Sent Items</item>
<item >Filing History</item>
</string-array>
</resources>
Have your string items as :
<string-array name="menu_items" >
<item >Demo Mode</item>
<item >Inbox</item>
<item >Sent Items</item>
<item >Filing History</item>
</string-array>
<string-array name="menu_items_labels" >
<item ><FONT COLOR="#006600"><b>Demo Mode</b></FONT></item>
<item ><FONT COLOR="#006600"><b>Inbox</b></FONT></item>
<item ><FONT COLOR="#006600"><b>Sent Items</b></FONT></item>
<item ><FONT COLOR="#006600"><b>Filing History</b></FONT></item>
</string-array>
In your spinner code - use:
// For setting the html code "menu_items_labels" with font color white
Spinner spinner = (Spinner) findViewById(R.id.my_spinner);
spinner.setAdapter(
new ArrayAdapter<CharSequence>(this,
R.layout.multiline_spinner_dropdown_item,
myActivity.this.getResources().getTextArray(R.array.menu_items_labels)));
To retrieve the String value (Without HTML Formatting),
strTemp = getResources().getStringArray(R.array.menu_items)[spinner.getSelectedItemPosition()];
You can not directly tell the (array) resource which color it should have. You either can define an app-wide theme/style to use for list items or create an Adapter with custom view, in your case an ArrayAdapter will fit best.
Hot to create an ArrayAdapter with a custom view.

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