Creating a custom adapter

The ArrayAdapter<Type> instances are really powerful and easy to use. However, they do lack flexibility. Indeed, you cannot populate a ListView instance or spinner with a business object of your own, for example. In this recipe, we will learn how to create a custom adapter.

Getting ready

Create two C# classes in the Populating ListView project named States and StateAdaptor, respectively.

How to do it...

  1. Add the following code in the State class:
    public class State { private string _Name; public string Name { //set the state name set { this._Name = value; } //get the state name get { return this._Name; } } private int _Pop; public int Pop { //set the state pop set { this._Pop = value; } //get the state pop get { return this._Pop; ...

Get Xamarin Studio for Android Programming: A C# Cookbook now with O’Reilly online learning.

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