Search

Xamarin Android ListViews - Basics

Monday 6 October 2014

This is the first in a series on Android ListViews in Xamarin. We look at how to show a basic list of strings using a ListActivity and an Array Adapter. We also look at handling clicks on list items.You can get the source code for all of my ListView articles here.

All of these examples are based on a ListActivity. By default this will give you an interface which is just a list. If you need a more sophisticated layout you can use a ListActivity with a custom layout (covered later in the series).
Here we use an ArrayAdapter as a ListAdapter. This is really simple, it takes a list of strings and then deals with showing them in the list. When it's running it looks like this...



Handling Item Clicks

To handle item clicks we can override OnListItemClick. Here we just popup some toast.

Alternatively you can subscribe to the click event. For long clicks you always need to subscribe to the event. Subscribe in the OnCreate method.
And then handle the click.

1 comment:

  1. Good sharing on series post on Android ListViews in Xamarin. Hire Xamarin Authorized Partners for your Xamarin Apps Development.

    ReplyDelete