Xamarin Android → Xamarin Android – GridView – Next/Previous Pagination – Camposha

Xamarin Android

Xamarin Android

Xamarin Android – GridView – Next/Previous Pagination

 

In this example we shall see how to implement a simple Next/Previous type of pagination in xamarin android.C# is our language of course.We generate data dynamically and page/paginate data.

If we reach the last page of course teh next button is disabled while if we are in the first page the previous button is disabled.

Intro

  • We page/paginate data in our GridView.
  • We fill the gridview with data that we generate.
  • If you click next we push you to the next page,while if you click previous we take you to the previous page.
  • If we reach the last page,the next button is disabled so you can move forward.We do the same with the first page with the previous button.
  • We use GridView as our component.
  • We’ve used Visual Studio as our IDE.
  • The code is well commented for easier understanding.

Common Questions we answer

With this simple example we explore the following :

  • How to page/paginate data.
  • Xamarin android pagination.
  • Next/Previous pagination example in android xamarin.
  • C# xamarin GridView tutorial.
  • How to paginate an arraylist.
  • Using Xamarin Android with GridView.

Tools Used

  • IDE : Visual Studio 2013
  • OS : Windows 8.1

Source Code

Lets start.

MainActivity Class

  • Our MainActivity,launcher activity.
  • First we reference views here,our GridView as well as next and previous buttons.
  • We initialize a counter variable to track the current page.
  • We increment or decrement this variable depending on the button the user clicks.

Paginator Class

  • This class pages/paginates our arraylist,returning the current page.
  • Its also responsible for generating dummy data.
  • We also hold the constants that determine how we page our data.

Main.axml Layout

  • Main Layout.
  • We specify Views and widgets xml code here.
  • This layout shall get inflated into our MainActivity interface.
  • We have a GridView,and two buttons : next and previous.

Result

  • Here’s what we get when we run the project.

Xamarin GridView Pagination Page One

Xamarin Android GridView Last Past Page

How To Run

  • Download the project above.
  • You’ll get a zipped file,extract it.
  • Open the Visual Studio.
  • Now close, already open project
  • Import the project.

More

YouTube

  • Visit our channel for more examples like these.

Facebook

 

Leave a Reply

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

Join Us
X