Using grids

We noted how lists are important. However, what if we plan to present our data as a grid? Lucky for us!! The Android Framework provides us with a GridView that works very similar to ListView. You define your GridView in layout and assign the adapter instance to GridView's adapter property. GridView will recycle all views for you and perform instantiation when needed. The main difference between the list and the grid is that you have to define the number of columns for your GridView. The following example will present you with an example of GridView's use:

 <?xml version="1.0" encoding="utf-8"?> <GridView xmlns:android="" android:id="@+id/my_grid" android:layout_width="match_parent" android:layout_height="match_parent" ...

Get Mastering Android Development with Kotlin now with O’Reilly online learning.

O’Reilly members experience live online training, plus books, videos, and digital content from 200+ publishers.