Reputation: 3644
I am trying to put the characters '<' '>' in a string resource.
If I use the HTML encoding inside the string:
<>
it works in the first build. However, after another build of the project, something automatically converts it to:
&lt;&gt;
So I can't use the previous encoding...
Trying to put "<" or even "\<" in the string will generate an XML error.
Trying to use CDATA will have the same behavior as above.
How do I put a '<' or '>' character with this crap?
UPDATE
I have added the "eclipse" tags, since after some discussion, it seems like an eclipse problem - something automatically edits my XML files. The updated question is - why does eclipse sometimes mess up my strings.xml file and try to encode special characters on its own?
Upvotes: 0
Views: 2395
Reputation: 3644
My current workaround is to use a hard-coded string in my Java class.
String s = "<M>";
mTextView.setText(s);
The other obvious given answer (using CDATA) is theoretically correct, so I'll +1 it, but it fails to work in my Eclipse environment after several build cycles, as Eclipse converts the CDATA section to an encoded string (and then my string displays "CDATA..." in my app).
Since I haven't found a cleaner solution, that's the answer.
Upvotes: 0
Reputation: 2669
This should work
<string name="angle_bracket">
<![CDATA[
<
]]>
</string>
if it's not, there problem is some where else in your project. (you can be sure by trying it in a new android project)
Upvotes: 2