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?

3 Answers 3

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"
 />
Sign up to request clarification or add additional context in comments.

2 Comments

I already saw that link but i dont want any error on my code :/ is there any way to avoid this error ?
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
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.

Comments

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.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.