Implementing a ListView
Almost all apps have some sort of collection of data that will be presented to the user, with the easiest and most common way being some sort of list.
How to do it...
If we want to present a collection of items to the user, we can use a ListView
instance:
In order to show a list, we need to add a
ListView
element to our layout resource (we can do this in the code as well):<ListView android:layout_width="match_parent" android:layout_height="match_parent" android:id="@+id/listView" />
We then get hold of the
ListView
instance in our code so that we can use it:ListView listView = FindViewById<ListView>( Resource.Id.listView);
Now that we have the view, we need the data (which we will generate here):
IEnumerable<int> numbers = Enumerable.Range(1, 1000); IEnumerable<string> strings = numbers.Select( i => string.Format("Item Number {0} Here!", i)); List<string> data = new List<string>(strings);
We then create an
IListAdapter
instance...