7

new dev here and hoping someone can help me, i have looked and cannot seem to find an answer to my question, i have all my textviews @strings but i am wondering, i have a textview that has an empty value in my xml on android studio i.e android:text="", i have to leave this empty as this is to display a results from a string array.

So my question is how can i add this to @string values when it is empty? sorry for the noobish question but i have not been able to find the answer to my question!

thank you

0

4 Answers 4

26

A shorter version that does not generate a lint warning for the empty body of the xml tag:

<string name="empty" />
Sign up to request clarification or add additional context in comments.

Comments

5

Simply define a string like

<string name="empty"></string>

in your strings.xml file

6 Comments

would this work for localization as i read that all textviews need to be @string for different countries
Obviously. The name of the resource doesn't change. And since its value is fixed (not translatable), you only need to set it once, in the (default) values folder.
What about using @null for the value?
@ChefPharaoh I'd prefer "", since @null sounds like something that sets a value to NULL. And NULL != "".
this notation results in the lint warning, xml tag has empty body. This can be avoided by writing <string name="empty" />
|
2

Rather than creating the empty string resource, I'd suggest that if you do not have any default text you can just remove android:text="". That means blank.

It is not mandatory to put that property in your xml.

3 Comments

what about localization if the string is not referenced?
how will you localize blank? blank is blank in all locales. :)
if you have it blank in one locale and have some value in another locale then it is good to create <string name="strName"></string> for the locales you have blank. (as suggested in other answers). But if all locales have it blank, there is really no need for localization.
0

XML won't take white space by default it will trim the spaces, So use \u0020 inside string tag instead of blank or white space.

Example : <string name="whitespace">\u0020</string>

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.