How to Get Value From a Code Into XML on an Android

The Android development platform uses XML to set up layouts and static variables you use in your Java code. Each Android program includes an XML "resource" file you use to add a variable into the XML that you use in any section of your program. You open the XML file in the Android Eclipse software and add each variable you want to use.

Instructions

    • 1

      Open the Eclipse Java software from the Windows program menu. Open your Android project and the list of Android XML and Java source code files are shown in the left panel.

    • 2

      Click the "resource" directory to see a list of resource files which are formatted in XML. Double-click the "strings.xml" file to open it in the editor.

    • 3

      Add the string to your resource file. Add the following code within the "<resource>" and "</resource>" tags:

      <string name="mystring">This is my string value</string>

      Replace the "name" with the string name you want to use. The string value is between the opening and closing string tags.

    • 4

      Double-click the XML file for your Android program's screen setup. Each layout in your Android program is associated with an XML file and you insert your new string values into the layout XML files.

    • 5

      Add the string variable to your Android layout XML. For instance, the following code is an example of using the new string in an TextView screen:

      <TextView
      android:layout_width="fill_parent"
      android:layout_height="wrap_content"
      android:text="@string/mystring" />

Related Searches:

References

Comments

Related Ads

Featured