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

Get Xamarin Mobile Development for Android Cookbook now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.