android gridview example

GridView in Android :

The GridView shows items in a two-dimensional scrolling grid. you can use the GridView together with an ImageView to show a series of pictures. the following example demonstrates how to Use GridView in Android application. You can control the number of columns, their width, and relevant spacing.

Note : This example (Project) is developed in Eclipse Version Kepler,tested on Android 4.4.2 (KitKat Version) and SDK build-tools 22.6.3

Solution Stuff :

In Android, use the GridView, use the <GridView> element and put it into your UI file and use “android.widget.GridView” class to render a GridView.

Complete Code :

1. Open “res/layout/activity_main.xml” file. To use the “GridView ” element and put it into your UI file, such as the activity_main.xml file:

File : res/layout/activity_main.xml

2. Open “MainAcitvity.class” file and add following JAVA code.

First, you need to make the ImageAdapter class (which extends the BaseAdapter class) so it will bind to the Gallery view with a series of ImageView views. The BaseAdapter class acts as a bridge between an AdapterView and also the data source that feeds data into it. This is examples of AdapterViews are as follows code:

In specific, the getView() method returns a view at the specified position. during in this case, you returned an ImageView object.

Figure shows GridView Output in Android emulator :

android gridview example

Download Android GridView example Source code :

Leave a Reply