I have used the listpreference in my preference screen. I wants to show the image in list entries. I have used the code but I am getting image address instead of image in entries. Help me with this problem.
Here is my code:
preferencecheckbox.xml
<PreferenceScreen xmlns:android="http://schemas.android.com/apk/res/android">
<ListPreference
android:key="listkey"
android:title="select"
android:summary="Select type"
android:entries="#array/array"
android:entryValues="#array/value"/>
</PreferenceScreen>
array.xml
<resources>
<array name="array">
<item>#drawable/image1</item>
<item>#drawable/image2</item>
<item>#drawable/image3</item>
</array>
<string-array name="value">
<item>data1</item>
<item>data2</item>
<item>data3</item>
</string-array>
</resources>
Related
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>
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" />
I am developing an android application and would like to be able to create an array consisting of words from an xml file, but am unsure of how that would look. Any help is appreciated.
You can do this if you just need a preset list
In your res/values folder there should be an arrays.xml file if there isnt create it.
Then withiin the file add something like this
<?xml version="1.0" encoding="utf-8"?>
<resources>
<array name="myarray">
<item>first item</item>
<item>second item</item>
<item>third item</item>
<item>foruth item</item>
</array>
</resources>
then do access it do this
String[] text = getResources().getStringArray(R.array.myarray);
Is it Possible I can create a spinner with options and values.
<select name=test>
<option value="1">Baran</option>
<option value="2">Khan</option>
</select>
with the spinner XML:
<?xml version="1.0" encoding="utf-8"?>
<resources>
<string-array name="test">
<item Value="1">Baran</item>
<item value="2">Khan</item>
</string-array>
</resources>
How can I accomplish such target. As I need to pass Ids to the Server.
You have to manage two list and both are dynamic as you want.
Step to achieve :
Create two ArrayList<String>.Depend on your data type here i make as String Array.
Add value to ArrayList.
Create custom adapter and pass two list adapter in that and get value according that.
Add list to Spinner Adapter. Get the index or position of
the Spinner.
Follow same index to get value from second list value.
Send that value to server.
Task over
See Demo Example that will Guide you to make easy.
Enjoy !!!
Not the best but one approach would be to create another string array with the ids:
<?xml version="1.0" encoding="utf-8"?>
<resources>
<string-array name="test">
<item Value="1">Baran</item>
<item value="2">Khan</item>
</string-array>
<string-array name="testIDS">
<item>1</item>
<item>2</item>
</string-array>
</resources>
Now when item i is selected from array test you can get the id from item i in array testIDS.
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...