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:
Popular Posts
- Save LogCat to a Text File
- Perform an Action after Enter keypress on EditText
- android:ellipsize - Add an ellipsis(...) in a TextView
- android:nextFocusDown - Set Next Focus to a TextView/EditText
- Solution: error: Error parsing XML: unbound prefix
- Intent setType(String type) - How to Set an Explicit MIME data type
- android:nextFocusRight - Set the Next Focus Right to a TextView/EditText
- android:textColorHint - Set the Color of Hint Text in TextView/EditText
- Determine the Hex value for a color
- Cursor getColumnIndex - Get the Index for a Column Name