Android GridView Example

In this android tutorial you will learn about android simple and custom gridview example.

In Android, GridView is a ViewGroup that is used to display items in a two dimensional scrollable grid form. You might have seen image gallery in Android mobiles, it is created using GridView layout.

Here we will see two examples, one is simple GridView layout with some text and another is custom GridView layout with image and text.

Android GridView Example

Android Simple GridView Example

Make an android project with package name com.gridviewexample and add following code in respective files.

activity_main.xml

 

MainActivity.java

 

Output

Android Simple GridView Example

 

Android Custom GridView Example

Make an android project with package name com.gridviewexample and add following code in respective files.

activity_main.xml

 

custom_gridview.xml

 

MainActivity.java

 

ImageAdapter.java

 

Output

Android Custom GridView Example

When you will click on any item, its name will be displayed in a toast.

Comment below if you have any queries related to above android gridview example.

2 thoughts on “Android GridView Example”

Leave a Comment

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