Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Hardcoded string "Test", should use @string resource

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"
     />
 
</LinearLayout>

I don't want to use string in the second test. What should I do?

like image 796
Edli Avatar asked Aug 03 '12 11:08

Edli


2 Answers

No problem that you are using the string hardcoded or not. If you want further information you could look: https://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"
 />
like image 52
Tuna Karakasoglu Avatar answered Oct 20 '22 15:10

Tuna Karakasoglu


If you don't want this warning to bother you specifically on this View, you can use tools:ignore xml attribute to suppress it.

<TextView
  android:layout_width="fill_parent"
  android:layout_height="wrap_content"
  android:text="@string/Test"
  tools:ignore="HardcodedText" />

Note that you can also add it to a parent element to suppress warnings on its children.

like image 25
Pedro Rocha Avatar answered Oct 20 '22 15:10

Pedro Rocha