O'Reilly logo

Xamarin Mobile Development for Android Cookbook by Matthew Leibowitz

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

Using a BaseAdapter with arbitrary data

Sometimes, we need to have the flexibility to completely customize the way a datatype is rendered for each item. To do this, we can make use of the BaseAdapter type and custom item layouts.

How to do it...

If we want to specify an actual custom type, then we can create an adapter, derived from the BaseAdapter type:

  1. A list can bind to any data type collection, as long as we have an adapter that understands how to present each item. For example, we can bind to an arbitrary type:
    public class Person {
      public int Id { get; set; }
      public string Name {get;set;}
      public string Status {get;set;}
      public bool IsMale { get; set; }
    }
  2. The adapter that we will create can inherit from the generic BaseAdapter<T> adapter:
    public ...

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