I want to have some simple text in textView..
Like...(android & java)
means I exactly require \"and\" symbol in textView
If I\'m pro
Define a new string in strings.xml
with the value of "Bakeries & Dessert".
Then, in the layout declare
<TextView android:text="@string/your_string_value"></TextView>
Later edit:
Adding an invalid character for XML in another XML file to circumvent the limitation will obviously not work. However, if you use Eclipse, when you add a new value in strings.xml, the characters like &
, <
and >
will be automatically replaced by the HTML equivalents (&
<
>
).
Another way to solve this is using Unicode:
set your text in your xml to
android:text="@string/myNameHere"
In strings xml add the following line:
<string name="myNameHere">bakeries \u0026 desserts</string>
voilá!
Try to set the text by code
TextView tv = (TextView)findViewById(R.id.textview);
tv.setText("input");
using Html to encode/decode the text
Html.fromHtml(string)
The layout file is an XML file and has certain restrictions on which characters may be used. However, you can use XML escape sequences to display characters which have special meaning to XML. In this case, replace the "Bakeries & Dessert" with the string "Bakeries & Dessert" and you should get the behaviour that you require.
The layout files are just xml and the & symbol is not allowed by itself.
You will need to use &
instead
http://en.wikipedia.org/wiki/List_of_XML_and_HTML_character_entity_references#Predefined_entities_in_XML
Simply write it with amp followed by semi-colon as below:
android:text="Bakeries & Dessert"