So the following will create a ListView where the rows have their "primary" textview filled by the values array.
ArrayAdapter<String> adapter = new ArrayAdapter<String>(this,
android.R.layout.simple_list_item_2, android.R.id.text1, values);
Changing the third parameter to android.R.id.text2 sets the "secondary" textview. Is there any simple way to set both?
Best Solution
This questions ranks high with Google but I consider the given answer to be way too complicated. As pointed out in other answers, the desired functionality can be achieved using ArrayAdapter with a very easy trick.
You can override the getView method of the ArrayAdapter:
If you didn't notice: the trick is to supply
android.R.id.text1
as (principally unneccessary) parameter, otherwise the call tosuper
will cause an exception.Also, this solution does not make use of
TwoLineListItem
, which was deprecated in API 17.