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.
- 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.
- IDE : Visual Studio 2013
- OS : Windows 8.1
- 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.
- 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 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.
- Here’s what we get when we run the project.
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.
- Visit our channel for more examples like these.
- Lets share tips and ideas in our Facebook Page.