Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to solve this issue of Hardcoded string?

Tags:

android

[I18N] Hardcoded string "Happy Birthday Debashish", should use @string resource less... (Ctrl+F1)

Hardcoding text attributes directly in layout files is bad for several reasons: * When creating configuration variations (for example for landscape or portrait)you have to repeat the actual text (and keep it up to date when making changes) * The application cannot be translated to other languages by just adding new translations for existing string resources. In Android Studio and Eclipse there are quickfixes to automatically extract this hardcoded string into a resource lookup.

enter image description here

like image 464
Debashish Panda Avatar asked Dec 07 '15 09:12

Debashish Panda


2 Answers

Ths is not an error but a warning. As a general rule, you should never use hardcoded strings in your layout but always use string resources (which means the all strings are stored in one separate file where they are easily changeable for different languages and so on).

To convert a hard coded String to a string ressource:

  • put the curser on the hard coded string
  • press ALT + Enter
  • enter a name for your ressource
  • click OK

After you've done that the warning will be gone. Good luck...

like image 144
Bmuig Avatar answered Oct 12 '22 23:10

Bmuig


This is just a warning.
Define your string in string.xml file

Happy Birthday Debashish

and in textView use this string as

 <TextView
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:text="@string/string_name"
        />
like image 35
Navin Gupta Avatar answered Oct 13 '22 01:10

Navin Gupta