How to Format a Table on TextView for Android

The Android SDK includes a "Table" layout that lets you add a table of information to your Android apps. The "TextView" object is the screen on which the table renders, so you use the screen and the table layout together to display rows and columns of information. You use the Android SDK Eclipse software to add additional layouts to your apps.

Instructions

    • 1

      Double-click the "Eclipse.exe" shortcut on your desktop and load the Android app project in the editing software.

    • 2

      Add the "TextView" definition to the XML. The following code creates a TextView definition to the Android screen:

      <TextView
      android:layout_column="1"
      android:text="My Table Layout"
      android:padding="3dip" />

    • 3

      Double-click the main XML file you use to display the table. Add the table layout XML tag. The following code defines the table and stretches the table across the TextView, so it fills the screen with the table information:

      <TableLayout xmlns:android="http://schemas.android.com/apk/res/android"
      android:layout_width="fill_parent"
      android:layout_height="fill_parent"
      android:stretchColumns="1">
      </TableLayout>

    • 4

      Add columns to the table layout. You use another "TextView" object to display content in the table's columns. The following code adds a column to your table and displays "Hello World" in the column:

      <TableRow>
      <TextView
      android:layout_column="1"
      android:text="Hello World"
      android:padding="3dip" />
      </TableRow>

    • 5

      Save the changes and click the "Run" button in the main toolbar to open the new layout in the Android emulator, so you can review the changes.

Related Searches:

References

Comments

Related Ads

Featured