O'Reilly logo

Xamarin Studio for Android Programming: A C# Cookbook by Mathieu Nayrolles

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

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; ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required