Using custom ListView items

Using a list view, we can entirely customize the way each item looks. We don't have to stick to a simple template, but rather provide a much more detailed view.

How to do it...

All we need to do in order to create a custom item template is to create a custom layout, either by code or in a layout resource:

  1. First, we create the item template using normal layout files.

    For example, we can create a layout named ListItemLayout.axml with three content views—an image view and two text views:

    <?xml version="1.0" encoding="utf-8"?> <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="fill_parent" android:layout_height="wrap_content"> <ImageView android:id="@+id/icon" android:layout_width="wrap_content" ...

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.