Reputation: 317
I had seen an Android Tutorial that allows a simple android:text just like the example bellow:
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Android Application"
android:textColor="#ffffff" />
But in my eclipse, it says:
[I18N] Hardcoded string "Android Application", should use @string resource
What should I do?
I need to insert a lot of Text just like,
Accounting has begun since time immemorial. Consider this truth: God said unto Noah; “and every living thing of all flesh, two of every sort shall thou bring into the ark, to keep them alive with thee; they shall be male and female. Of fowls after their kind, and of cattle after their kind, of every creeping thing of the earth after his kind, two of every sort shall come unto thee, to keep them alive. And take thou unto thee of all food that is eaten, and thou shall gather it to thee; and it shall be for food for thee, and for them.” The Bible – Genesis 6:19-20. “Of every clean beast thou shall take to thee by sevens, the male and his female: and of the beast that are not clean by two, the male and his female. Of fowls of the air by sevens, the male and the female; to keep seed alive upon the face of all earth.” The Bible – Genesis 7:2-3
Any suggestion or tell me what the better thing to do?
Upvotes: 0
Views: 844
Reputation: 4712
You can use hardcoded strings in your layout (or in code), it is just a warning and eclipse won't fail on compilation.
But android best practice is the remove all strings and texts from your app and layout and put it in one place- so it will be much easier to translate later.
So what eclipse suggest you is to extract the "Android Application" text to strings.xml file (that should contain all your app's strings).
If it's just for the tutorial you can ignore it, or even better- just let eclipse extract the text to strings.xml using quick fix
Upvotes: 0
Reputation: 93872
This is just a warning.
But by using a string resource, you can support multi-languages.
You have just to create a new string resource in the file strings.xml
(res/values/strings.xml
).
Then add the line :
<string name="your_name">Your text</string>
and just change :
android:text="Android Application"
by android:text="@string/your_name"
Now if you want to add a new language to your application, let's say in french, you will have just to create a new folder in the res
folder called values-fr
and copy/paste the file strings.xml
you already have and finally translate the strings you have defined (i.e <string name="your_name">Your text translated in french</string>
)
You can have a look at this (problem resolved using screenshots).
Upvotes: 1