Let's say I have a listview with the id 'stringList', and an array called 'stringListContents'. How would I populate the listview from the array with index 0 being first obviously, and the list ending at array.getLength?
Asked
Active
Viewed 72 times
0
-
Possible duplicate of [Populate a Listview from a String-Array](http://stackoverflow.com/questions/17034316/populate-a-listview-from-a-string-array) – Rishabh Jan 11 '16 at 02:41
-
2Possible duplicate of [ArrayAdapter in android to create simple listview](http://stackoverflow.com/questions/19079400/arrayadapter-in-android-to-create-simple-listview) – Mike M. Jan 11 '16 at 02:48
2 Answers
3
If I undestand your question correcly, you could use something like this:
public class MyListActivity extends ListActivity {
...
public void onCreate(Bundle icicle) {
super.onCreate(icicle);
ArrayAdapter<String> adapter = new ArrayAdapter<String>(this,
android.R.layout.simple_list_item_1, stringListContents);
setListAdapter(adapter);
}

Slava Vedenin
- 58,326
- 13
- 40
- 59
1
ArrayAdapter<String> adapter = new ArrayAdapter<String>(this,
android.R.layout.simple_list_item_1, stringListContents);
stringList.setAdapter(adapter);

Krishna Satwaji Khandagale
- 2,235
- 16
- 25