Skip to content
Branch: master
Find file History
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Type Name Latest commit message Commit time
Failed to load latest commit information.

id title brief sdk
Use an ArrayAdapter
This recipe shows how to bind an array to a list using an ArrayAdapter.


Follow these steps to display an array of strings in a ListView, which have been provided by ListActivity.

  • Add a file named TextViewItem.xml under the Resources/layout folder containing the following XML.
<?xml version="1.0" encoding="UTF-8"?>
<TextView xmlns:android=""
    android:layout_height="wrap_content" />
  • In a ListActivity subclass, add the following code.
public class Activity1 : ListActivity
string[] data = {"one", "two", "three", "four", "five"} ;

protected override void OnCreate (Bundle bundle)
base.OnCreate (bundle);
ArrayAdapter adapter = new ArrayAdapter (this,
Resource.Layout.TextViewItem, data);
ListAdapter = adapter;

protected override void OnListItemClick (ListView l, View v,
int position, long id)
base.OnListItemClick (l, v, position, id);
Toast.MakeText (this, data [position],
ToastLength.Short).Show ();


Additional Information

An ArrayAdapter binds each object in an array to a TextView. The ListActivity class used here implicitly contains a ListView that can be bound to a data source through the ListAdapter property, causing each TextView instance to be presented in a list. Overriding OnListItemClick allows us to handle item selection.

You can’t perform that action at this time.