articles

Home / DeveloperSection / Articles / Resolving Hardcoded string, should use @string resource in Android Application

Resolving Hardcoded string, should use @string resource in Android Application

Shankar M17465 21-Apr-2013

                                              

Resolving Hardcoded string, should use @string resource in Android Application

When working with Android Application we might have faced this error after placing a button or other controls on the Form indicating that Hardcoded string should use @string resource.

 Here we will learn how to resolve this issue when working with our Android Application.

Structure of our Project

Resolving Hardcoded string, should use @string resource in Android Application

Here we, need to declare string variable for Button with the value that should be displayed in the Label of Button control.

This can be done by navigating to values Menu in the Structure displayed.

Resolving Hardcoded string, should use @string resource in Android Application

Double-click on the string.xml the Android Resource Elements is displayed,

Resolving Hardcoded string, should use @string resource in Android Application

Now, it’s time to declare a string variable for the Button control. Click Add button a screen pop-ups showing the creation of new element, select string and click OK.

Resolving Hardcoded string, should use @string resource in Android Application

Next, we declare the Name and value of the Element to be defined as shown,

Resolving Hardcoded string, should use @string resource in Android Application

Resolving Hardcoded string, should use @string resource in Android Application

Replace the Button Text property with the element name with the @string variable we have defined as like this,

android:text="@string/Btn_Cancel" />

And then, the XML File looks something like this,’

Resolving Hardcoded string, should use @string resource in Android Application

Now, once we switch over to Graphical Layout, the screen is as shown below.

Resolving Hardcoded string, should use @string resource in Android Application

Hope this might be useful a little.

Enjoy Coding!!!


Updated 10-Jun-2020

Leave Comment

Comments

Liked By