0% found this document useful (0 votes)
188 views2 pages

String Resource

- Stack Overflow is a question and answer site for professional and enthusiast programmers - A user asked why they should use a string resource instead of hardcoding a string in their Android layout XML - The answer explained that it is better to define strings in the strings.xml file and reference them using @string/ to avoid warnings and allow easy internationalization - The user's issue was resolved by adding the hardcoded string to strings.xml and referencing it properly in the layout XML
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
188 views2 pages

String Resource

- Stack Overflow is a question and answer site for professional and enthusiast programmers - A user asked why they should use a string resource instead of hardcoding a string in their Android layout XML - The answer explained that it is better to define strings in the strings.xml file and reference them using @string/ to avoid warnings and allow easy internationalization - The user's issue was resolved by adding the hardcoded string to strings.xml and referencing it properly in the layout XML
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 2

android layout - Hardcoded string "Test", should use @string resource - Stack Over...

Página 1 de 2

Stack Overflow is a question and answer site for professional and enthusiast programmers. It's 100% free, no
Tell me more ×
registration required.

Hardcoded string “Test”, should use @string resource

Hi guys I'm new here and this is my very first problem

here is my code:

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:orientation="horizontal"
android:layout_width="fill_parent"
android:layout_height="fill_parent" >

<TextView

android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/ref"
/>

<TextView

android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="Test"
/>

I don't want to use string in the second test what should i do ?

android-layout

asked Aug 3 '12 at 11:51


Edli
11 1 2

1 Answer

No problem that you are using the string hardcoded or not. If you want further information you could look:
http://stackoverflow.com/a/8743887/1517996

strings.xml

<resources>
<string name="Test">Test</string>
<resources>

and use it lin layout file like

<TextView

android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="@string/Test"
/>

edited Aug 3 '12 at 13:21 answered Aug 3 '12 at 11:56


CodersParadise
477 1 10

I already saw that link but i dont want any error on my code :/ is there any way to avoid this error ? – Edli Aug
3 '12 at 13:14

http://stackoverflow.com/questions/11795206/hardcoded-string-test-should-use-string... 03/10/2013
android layout - Hardcoded string "Test", should use @string resource - Stack Over... Página 2 de 2

this is not an error, this is a warning. If you dont want this warning you should implement your "Test" string in
strings.xml as <string name="Test">Test</string> and use it like <TextView android:layout_width="fill_parent"
android:layout_height="wrap_content" android:text="@string/Test" /> please see my edited post –
CodersParadise Aug 3 '12 at 13:20

Thanks alot !!! You really help me – Edli Aug 3 '12 at 13:51

:) If it is correct please mark as an answer. – CodersParadise Aug 3 '12 at 14:06

1 Why wasn't this answer accepted? – Aaron Russell Apr 26 at 17:27

Not the answer you're looking for? Browse other questions tagged android-layout or
ask your own question.

http://stackoverflow.com/questions/11795206/hardcoded-string-test-should-use-string... 03/10/2013

You might also like