Praveenbabu Praveenbabu - 2 years ago 103
Android Question

Difference between android:text="@string/hello" and normal right click--> Text view component--> EditText

While I am working with help of tutorial I found this in textview android:text-"@string/hello" it shows some error.

Then I went through graphical view and right click the component and enter the text. Then that error removes and notifies me that

**Hardcoded string hello should use String resources**

Answer Source

In android, "@string/" refer to the string.xml in Project>res>values> location in your package explorer.

String.xml contains a xml file which refer to a string with an id. Eg:

<?xml version="1.0" encoding="utf-8"?>
    <string name="hello">Hello World</string>
    <string name="app_name">My app</string>

Here name="hello" is the id & "Hello World" is its value. When @string/hello is used, the value will be shown.

Similar is the case with "@drawable/". It will refer to the images used. and many more.

You can set text in text view pragmatically: Eg:

TextView tv = (TextView)findViewById(;     //text1 is the id u provide in xml file
tv.setText("Hello World");

I hope it helped you.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download