5

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?

peterh
  • 11,875
  • 18
  • 85
  • 108
Edli
  • 59
  • 1
  • 1
  • 4

3 Answers3

14

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"
 />
Community
  • 1
  • 1
Tuna Karakasoglu
  • 1,262
  • 9
  • 28
  • I already saw that link but i dont want any error on my code :/ is there any way to avoid this error ? – Edli Aug 03 '12 at 13:14
  • 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 Test and use it like please see my edited post – Tuna Karakasoglu Aug 03 '12 at 13:20
2

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.

Pedro Rocha
  • 154
  • 6
0

You can use hardcoded value, it's fine. If you want to remove the warning, you can go to Eclipse -> preference -> Android -> Lint Error Checking and look for "Hardcoded Text". Set it to ignore then Apply.

pierre23
  • 3,846
  • 1
  • 28
  • 28