ANDROID

How to create simple GridView in Android

How to create simple GridView in Android

Simple GridView in Android

Grid View is one that displays the data in two-dimensional scrolling grid. Adapter associated with the Grid View loads the data into the Grid View from different sources like array or cursor containing query result.

I am going to show you how to create simple Grid View having single Text View in each of the grids. Let’s start,

Create the new project as File->New->New Project. Give a project name as SimpleGrid-> rename MainActivity as SimpleGridActivity and select Finish.

Go to res->layout->activity_simple_grid.xml. Copy the below code in the Text tab of activity_simple_grid.xml.

Now create a new xml file that represents single grid item in res ->layout ->right_click -> grid_item.xml. Copy the below code in Text tab of grid_item.xml.

As I already mentioned that I am creating a grid view containing single Textview, that is why I am using  ArrayAdapter of type String only. We will see the custom adapter for grid view as well. Open SimpleGridActivity.java from java directory and copy the below code.

For a click on a grid, you need to add the onClick event in your SimpleGridActivity as follows.

The final SimpleGridActivity will as below.

Your AndroidManifest.xml will be as below.

Now run the App you will have the following output.

Simple Grid View in Android with click on its grid.

Simple Grid View in Android with click on its grid.

Here we did with the simple Grid View with a click on its grid. Hope you understand it clearly, if you do not understand anything don’t hesitate to comment below. I would love to help you.

Click to comment

Leave a Reply

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

Most Popular

Buzzing your life from assorted Coding,tips and general life opinion. Made your life Buzz by BuzzMyCode articles, share with world.

What is Buzzmycode, we had started this website to give tech savy the new way of life by reading our fresh organic content on every technology and applications.

Copyright © 2017 SyncSaS. Theme by SyncSaS Themes, powered by BuzzMyCode.

To Top