Simple Android GridView Tutorial with Example

GridView is one of the useful and powerful android components which allows us to display different items in two dimensional scrolling grids. All the items of grid are automatically to the layout using ListAdapter. GridView is necessary when we want to display data in grid layout like news application - Play NewsStand, image view app - Pintrest, Play Music, and Calendar App etc. In this tutorial you will learn to create a simple android application using GridView.

GridView has many attributes which allows you to customize your app. In this sample gridview example I have added some text in grid box. You can add image, image and text and many more. Following is the step by step guide to implement GridView in android.

Floating Action Button (FAB) with Android ListView
Android ListView with Image and Text
Android Linear ListView Example

Android Example: How to Make Simple Application Using GridView

Here you will learn to make simple android application using GridView with a simple way and little bit code. Following is the content of two different file java activity file and xml layout file.

XML layout File

Open your XML layout file and add a GridView component inside any layout or as root layout. And then give an id to it add android:numColumns="auto_fit” and android:stretchMode="columnWidth" attributes, you can also set android:columnWidth="100dp" as well as. Following is the complete content of XML layout file.


Java Activity File

Open your java activity file and add some array strings like static final String[] gridViewStringValue = new String[]{… }; and pass these string to GridView using ArrayAdapter, you can also set on click listener. Following is the complete java activity file of GridView sample example app.


Android Example: How to Make Simple Application Using GridView

Now, run your Simple Android GridView Tutorial with Example application and click on the grid item, you will see the toast message. GridView is like the listview, if you are familiar with android listview than it will be easy to understand GridView.
UI 686500012323980410
Home item