Reputation: 57
hi have problem when i view graphical.layout of this file
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="vertical" >
<TextView
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="@string/hello_world" />
<TextView
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="this is main text" />
</LinearLayout>
when i view graphical layout of this view this xml file then this warning show [I18N] Hardcoded string "this is main text", should use @string resource but i dont want to declare string valiable i want to show this "this is main text" without declaring string
Upvotes: 0
Views: 474
Reputation: 13632
If you want to suppress the specific warning use tools:ignore="HardcodedText"
more details http://tools.android.com/recent/ignoringlintwarnings
Upvotes: 0
Reputation:
You must declare your text using `@string` resource that
is a good programming format.You should prefer using
`string.xml` in value folder in res folder if you want
to use texts.
Upvotes: 0
Reputation: 751
The warning about 'should use @string resource' is just a reminder that locale-specific information should be placed in 'resource bundles' (eg /res/values/strings.xml) so that labels and other text can be provided in different languages without having to re-code and recompile the entire application for each language.
If you're just testing things out, you can safely ignore that warning, but it's a good idea to get in the habit of referencing strings as resources in external files rather than hardcoding them directly in the application itself.
It is not good practice to hard code strings into your layout files. You should add them to a string resource file and then reference them from your layout.
refer this answer and this one also.
Upvotes: 1