Android Simple Table Layout Tutorial

Table Layout is a ViewGroup same as Linear Layout and Relative Layout, it is good for displaying a table in the android application. The feature of table layout is almost similar to the html in the website. It contain row and column to let the developer to customize according their need. In this tutorial, I will teach you some steps to implement android simple table layout tutorial and insert the table row programmatically.

Creating a New Project

1. Open Android Studio IDE in your computer.
2. Create a new project and Edit the Application name to “TableLayoutExample”.
(Optional) You can edit the company domain or select the suitable location for current project tutorial. Then click next button to proceed.
3. Select Minimum SDK (API 15:Android 4.0.3 (IceCreamSandwich). I choose the API 15 because many android devices currently are support more than API 15. Click Next button.
4. Choose “Empty Activity” and Click Next button
5. Lastly, press finish button.

Add new xml for table cell shape

Go to res > Right click drawable > new > Layout resource file and name it to cell_shape.xml. After that edit it to the following source code so your table will have the rectangle border.

Add new xml layout for table row

Go to res > Right click layout > new > Layout resource file and name it to table_item.xml. After that edit it to the following so it will able to add the row into the table layout.

Edit activity_main.xml layout

Navigate to the activity_main.xml in your layout folder and add the table layout so it will able to show table later.

Edit class

Now, you go to your class to perform some java code so it can add the table_item to the table layout. You can follow the source code in the bottom.

Run your project

In the end, you can run the perfect working table layout in your android device or emulator.

(Android Simple Table Layout Tutorial)

Source Code

(Visited 1,709 times, 1 visits today)

Yong Loon Ng

Ng Yong Loon, better known as Kristofer is a software engineer and computer scientist who doubles up as an entrepreneur.

You may also like...

1 Response

  1. Pradip says:

    res > Right click drawable > new > Layout resource file , this option doesn’t exist

Leave a Reply

Your email address will not be published. Required fields are marked *