Android: Populating a listview with array items Android: Populating a listview with array items arrays arrays

Android: Populating a listview with array items


For code, take a quick look at this step-by-step tutorial

setListAdapter(new ArrayAdapter<String>(this, R.layout.list_item, COUNTRIES));  ListView lv = getListView();

It shows a basic implementation of an ArrayAdapter:

R.layout.list_item : is the xml layout (list_item.xml) that will be used for every ROW of yourlistview.COUNTRIES is the array of Strings.


You can use an ArrayAdapter to bind your data. Since you want to be able to add extra data items to the view, you to give the adapter an ArrayList (since an array is of a fixed size). Items should be added via the ArrayAdapter and your ArrayList will be updated automatically. I have an example at http://www.box.net/shared/yduel9txya