Warning : Hardcoded string "str", should use @string resource

Eclipse sometimes show a warning "Hardcoded string "str", should use @string resource.", while compiling an Android project. 
E.g: you might have used text view as below, and set the text directly in the layout xml



    <TextView
        android:id="@+id/textView1"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="This is text View" />

Resolution: Declare the string resource in strings.xml, present under values folder. Use the variable instead of the value that you have set.   


E.g.: for above text view declare string resource  as below :
 <string name="info">
This is text View
</string>


and update the text view as below:

    <TextView
        android:id="@+id/textView1"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="@string/info" />

5 comments:

  1. android:id="@+id/button1"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_alignRight="@+id/editText2"
    android:layout_below="@+id/textView1"
    android:layout_marginTop="52dp"
    android:text="button">

    how can i use string resource can you explain me? please

    ReplyDelete
    Replies
    1. Create strings.xml under \res\values directory of your project in the eclipse if not exists. Place the code

      <resources>
          <string name="button_Name">Button</string>
      </resources>


      Save the xml file.
      if xml is already exist, ideally it should be then add below line in xml as:


          <string name="button_Name">Button</string>



      Save the xml. Now modify your code as
      android:text="@string/button_Name">

      Delete
  2. Iam getting this warrning:"Attribute is missing the Android namespace prefix"

    This is my code




    text



    ReplyDelete
    Replies
    1. I can't see your code can you paste it as a normal text?

      Delete

Golang: Http POST Request with JSON Body example

Go standard library comes with "net/http" package which has excellent support for HTTP Client and Server.   In order to post JSON ...