user1795999
user1795999

Reputation: 301

"Hardcoded string xxx should use @string resource" issue

I'm getting the following error in hello world activity code:

Description Resource Path Location Type
[I18N] Hardcoded string "and this is a clickable button!", 
    should use @string resource
activity_hello_world.xml/HelloWorld/res/layout line 21 Android Lint Problem

Please help me out.

Upvotes: 9

Views: 39307

Answers (2)

jyoti
jyoti

Reputation: 1

example- (of keypad)

put this under file string.xml under values folder

<string name="keypad_title">Keypad</string>

put this code under keypad.xml under layout folder

<Button android:id="@+id/keypad_1"
     android:text="1">
  </Button> 

Upvotes: 0

Ahmad
Ahmad

Reputation: 72533

This is not an error, this is a Lint warning. So you can run the App, but the recommended way to display texts(on TextViews, Buttons etc.) is to use string references. You have to go to your res folder and there will be a strings.xml file under values. Add this in there:

   <string name="my_string">Your Text!</string>

And to set text on you button you then have to do this:

android:text="@string/my_string"

Upvotes: 18

Related Questions