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
- Perform an Action after Enter keypress on EditText
- android:ellipsize - Add an ellipsis(...) in a TextView
- Intent setType(String type) - How to Set an Explicit MIME data type
- Create a Drawable Object Variable
- android:scrollbarStyle - Change the Scrollbar Location/Style in a TextView
- How to Register an Activity that Responds to NFC tags for URI's that point to a URL
- Solution: Running Android Lint has encountered a problem Failed
- How to Declare a new HttpURLConnection
- android:alpha - Set the Opacity/Transparency of Text in TextView/EditText
- MenuInflater - How to Inflate a Menu