//ENG
I don't know English, I may have mistakes, sorry.
Hello there...
I want to random text, but somewhere there was a problem.
Where the problem is located
//TR
Merhaba...
Random text yapmak istiyorum ama bir yerde sorun çıktı.
Sorunun bulunduğu yer
Kodlarımın tamamı ise aşağıdadır.
There is a empty line in the start of the strings.xml file remove the empty line.
<?xml version="1.0" encoding="utf-8"?>
Remove this line from top
<resources>
<string name="app_name">JarTest</string>
<string-array name="status">
<item>Available</item>
<item>Busy</item>
</string-array>
</resources>
Related
I am relatively new to android, so please be patient. In my project, I need two spinner objects and therefore need two different string-arrays within my strings.xml resource file. When I try to add the second string-array to the xml and run the app, I get a resource compilation failed error. It points to :app:mergeDebugResources which failed. I don't really know what else is wrong aside from this one message, as there is nothing that populates in the Logcat window. Please let me know if more info is needed.
<resources>
<string name="app_name">MindYourPet2</string>
<!-- TODO: Remove or change this placeholder text -->
<string name="hello_blank_fragment">Hello blank fragment</string>
<string name="submit">submit</string>
<string name="pet_profiles_title">Pets</string>
<string name="add_pet_title">Add Pet</string>
<string name="reminders_title">Reminders</string>
<string-array name="species">
<item>-</item>
<item>Cat</item>
<item>Dog</item>
</string-array>
<string-array name="frequency">
<item>Don't Repeat</item>
<item>Every Day</item>
<item>Every Week</item>
<item>Every Month</item>
</string-array>
I think the problem could be a syntax error in the XML preventing Android Studio/SDK from finishing the parsing of your XML resources for generation of things such as R.java
One problem I notice in your XML is that apostrophe needs escaping.
<item>Don't Repeat</item>
Should be
<item>Don\'t Repeat</item>
This way it does not treat the apostrophe as a quote and cause problems in the format of the XML, it instead treats it like any other character.
I'm trying to set an android app project.
In their documentation it's written that:
Simply find and edit res/values/config.xml file in the project folder. Change "banner_ad_unit_id" for Banner ads and "interstitial_add_unit_id" for Interstitial ads and you are finished. If you don't want AdMob in your app, simply remove key and string tags.
But when I removed contents of strings or the whole string, in both case I got lots of errors:
<?xml version="1.0" encoding="utf-8"?>
<resources>
<string name="banner_ad_unit_id" translatable="false">ca-app-pub-5514315741534690/1584741164</string>
<string name="interstitial_ad_unit_id" translatable="false">ca-app-pub-5514315741534690/4538207562</string>
<string name="ad_app_id" translatable="false">ca-app-pub-5514315741534690~9108007962</string>
<string name="test_device_id" translatable="false">7170163625397D22C4A4E1FD60819BAF</string>
Please keep in mind that I'm really a newbie in Android Studio, so I apologize if my question is too much simple.
The Keys are "name=abc" and the value is the value inside of ">xyz<"
So just delete xyz:
<?xml version="1.0" encoding="utf-8"?>
<resources>
<string name="banner_ad_unit_id" translatable="false"></string>
<string name="interstitial_ad_unit_id" translatable="false"></string>
<string name="ad_app_id" translatable="false"></string>
<string name="test_device_id" translatable="false"></string>
If you you remove the requests for an ad in your code you can also delete the entire section because the values are already empty and nothing would happen.
All,
I have the following in my string resource xml file.
<?xml version="1.0" encoding="utf-8"?> <resources>
<string name="hello">Hello World, ProDroid_Android!</string>
<string name="app_name">ProDroid_Android-CH3-Resources</string>
<plurals name ="eggs_in_A_basket">
<item quantity ="one"> There is 1 egg</item>
<item quantity = "other"> There are %d eggs</item>
</plurals>
<string name="simple_string">simple string</string>
<string name="quoted_string">"Quoted String 'xyz' string"</string>
<string name="double_quoted_string">\"Double Quoted String\""\";</string>
<string name="java_format_string">Hello %2$s Java format String. %1$s again.</string>
<string name="tagged_string">Hello <b><i> Slanted Android.</i></b>, You are bold</string>
When I go to put the tagged_string into a TextView with the HTML formatting it does not display with it's formatting. However, if I cut and paste the Hello Slanted Android., You are bold and manually put it into .setText it works, or if I set it statically in my layout xml file. However using the Java code below it does not work (All you see is unformatted text):
//HTML
TextView t6 = (TextView) findViewById(R.id.textView6);
t6.setText(Html.fromHtml(ProDroid_Android.this.getString(R.string.tagged_string)));
Any help would be appreciated.
Thx
If you format your text in XML it isn't necessary to use Html.formatHtml(...)
Try this:
t6.setText(getString(R.string.tagged_string);
EDIT:
Hmm... This way worked for me fine and I tried exactly your String.
Maybe your Project needs a clean (Project > Clean ...)
If this doesn't help:
I found another question. Maybe the answer there can solve your problem
i am using Eclipse 3.7.2.
I dont know why but the last line leads to an error highlightning
<string name="app_name">Test</string>
<string name="title">#string/app_name</string> <!-- works //-->
<string name="txt_text">Checkout #string/app_name this works</string> <!-- works //-->
<string name="txt_recommend">#string/app_name is not working</string> <!-- error //-->
is there a work around?
I believe you can't mix references and text in the XML. Use formatting placeholders instead.
http://developer.android.com/guide/topics/resources/string-resource.html#FormattingAndStyling
Instead of
<string name="app_name">Test</string>
<string name="txt_recommend">#string/app_name is not working</string>
this would look like
<string name="app_name">Test</string>
<string name="txt_recommend">%s is not working</string>
And in the code:
String text = String.format(res.getString(R.string.txt_recommend), res.getString(R.string.app_name));
The error is probably from the second last line rather than the last line.
<string name="txt_text">Checkout #string/app_name this works</string>
In this line you seem to be mixing text ("Checkout" and "this works" ) with a reference ("#string/app_name")
I dont think you can do that just in xml.
Ok, so this question is a bit weird, and kinda rubs me the wrong to even ask, but since I probably don't have a choice I want to see what you guys think. I'm still a novice at Java and Android.
The case is as follows: We are trying to automate the building of our strings.xml for localisation. A parser has been made to convert a csv-file to xml. For regular strings it's not a real problem, that works fine. But the parser that was built, doesn't take string arrays into account and there is little chance that someone will modify it.
Is there an "easy" way to work with the strings and create an string array programmatically based on parts the name attributes?
If not, then I would have to hard code the arrays and that leaves the creator (client) of the language files unable to add items to something that should be a dynamic list.
I know modifying the strings.xml manually might be an option, but because our management wants to automate stuff like that, it's not much of a choice I have.
Probably I will hard code the stuff and say they can't dynamically fill the lists, but still (also for my personal education) I wanna know what you guys think.
Thanks for your opinions or solutions. :)
Cheers!
You can use (& really really really should anyways) references in string arrays. Assuming this is your generated res/values/strings.xml in Swedish:
<?xml version="1.0" encoding="utf-8"?>
<resources>
<string name="string1">Hej, detta är på svenska</string>
<string name="string2">Denna strängen också</string>
</resources>
You can put your string-array in, for instance, res/values/arrays.xml:
<?xml version="1.0" encoding="utf-8"?>
<resources>
<string-array name="somearrayname">
<item>#string/string1</item>
<item>#string/string1</item>
</string-array>
</resources>
So you will get strings.xml as below
<?xml version="1.0" encoding="utf-8"?>
<resources>
<string name="string1">1st string</string>
<string name="string2">2nd string</string>
........
<string name="stringN">Nth string</string>
</resources>
I suggest a simple modification to strings.xml, which is add a string with name count at top of all strings with value equal to total number of strings and add another string with name prefix below the count, then it looks like as below.
<?xml version="1.0" encoding="utf-8"?>
<resources>
<string name="count">4</string>
<string name="prefix">string</string>
<string name="string1">1st string</string>
<string name="string2">2nd string</string>
<string name="string3">3rd string</string>
<string name="string4">4th string</string>
</resources>
So now, in your java file you can access them like below
int count = Integer.parseInt(getString(R.string.count));
String prefix = getString(R.string.prefix);
String[] strings = new String[count];
for (int i = 0; i < count; i++) {
strings[i] = getString(getResources().getIdentifier(prefix+(i+1), "string", getPackageName()));
}
I hope it may help you.