Kotlin GridView example: Show List of Items on Grid | Android

GridView is an Android ViewGroup that can show items in a 2-dimensional, scrollable grid. The grid items will be inserted to the layout using an Adapter. In this tutorial, we’re gonna create an Android App that can show List of Items on a Grid using GridView.

More Practice: Kotlin GridView example: Show Item Details | Android

Related Post: Kotlin ListView example | Android

I. Technologies

– Android Studio 3
– Kotlin 1.1.51

II. Overview

1. Goal

We will build an example that uses GridView to show list of food items like this:
kotlin-gridview-goal

2. Project Structure

kotlin-gridview-project-structure

III. Practice

1. Set up Project

– Create New Project:
kotlin-gridview-create-project

– Add each item insides sample_images to res/drawable folder.

2. Layout
2.1 Container Layout

Open res/layout/activity_main.xml file:

2.2 Item Layout

Add food_entry.xml file to res/layout folder:

3. Logic
3.1 Item Class

This class represents data of each Food Item:

3.2 Activity Class

We will:
– Create a BaseAdapter subclass.
– Set an instance of this class as data provider to the GridView.
– Return each cell’s view from getView() on your adapter.

IV. Source Code

Kotlin-GridView

By JavaSampleApproach | December 2, 2017.


Related Posts


Got Something To Say:

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

*