How to Link a String Array to an ArrayAdapter

ArrayAdapter was added in API level 1

1. Create an String Array to link to your ArrayAdapter. Name this array, myArray.

2. Create an ArrayAdapter.

3. Open the MainActivity.java file and add the below code to the onCreate method. The row layout that should be used for each row is named android.R.layout.simple_list_item_1. This uses the Android stock list item xml file of android.R.layout.simple_list_item located in your Android platform directory. You may use your own row layout instead, defined in res\layout directory.

myArrayAdapter = new ArrayAdapter<String>(this, android.R.layout.simple_list_item_1, myArray);

4. Compile and run!

5. Here are some other stock list row item xml files:

test_list_item.xml - API 10
simple_list_item_2.xml - API 10
simple_list_item_checked.xml - API 10
simple_list_item_multiple_choice.xml - API 10
simple_list_item_single_choice.xml - API 10

simple_list_item_activated_1.xml - API 11
simple_list_item_activated_2.xml - API 11
simple_selectable_list_item.xml - API 11

simple_gallery_item.xml - API 13

simple_list_item_2_single_choice.xml - API 19

Resources: