We are going to add multiple columns to our listview. We have implemented a basic listview in the previous articles. This tutorial presents an example to use custom adapters to implement a multicolumn listview in Android.

What is a listview?

A ListView is group of views that displays a list of scrollable items. A basic listview is a combination of multiple rows and one column.

Why do we need to create an Android multicolumn ListView?

We use it to display data in a table format. In this example, we are creating one Android application to display the name, gender, age, and marital status of a person.

Screenshot of an Android Application

multicolumn listview app

To create a custom layout for our multicolumn listview we need to add four textviews. Let’s create a new Android xml file.


How to divide the multicolumn listview screens.

We have to set the width to be 0 dp so it will automatically adjust its size. We have given the weight of 1 for name, gender and marital status. The weight of the age TextView is 0.5. Now the columns in our listview are divided into four parts. Three parts are equal and one part is half of any other individual.

Now let’s implement the main activity layout for our multicolumn listview Android example.


Now we need to create some constants for our application. We need to add 4 columns to our listviewview. Declare four strings for these columns.


A Custom adapter for an Android multicolumn listview

We need to implement a custom adapter for creating a listview with multiple columns. We have four columns in our listview. We will use a HashMap to store 4 values. The adapter helps to inflate the layout. You can learn more about them in the listview adapters tutorial.


In the above code we have fetched data from the hashmap. We have plugged data into 4 textviews. A custom listview adapter helps to convert textual data to Android user interface elements. It returns an inflated layout which gets displayed on your Android screen. Now let’s create the main activity for a multicolumn listview example.


How to pass data to a multicolumn listview.

In the main activity file, we have used a hashmap to pass data to the listview. The code snippet given below shows an example to pass data to a hashmap.

Similarly, you can create data for multiple rows. Then you need to use a custom adapter to display data inside a listview.

 How to handle a click event inside a listview.

This part is the same as a simple listview click event. In the multicolumn listview tutorial, we have displayed a toast message for the click event. Refer to the below code to understand the click functionality.

What Next?

You can learn how to add a checkbox to a listview. Adding a checkbox to your listview gives you the functionality of selecting multiple rows.


We have successfully implemented an Android multicolumn listview. If you want to share something, please feel free to do so in the comment section given below.