Multi-Line ListView Entries in Android

How to Place Multiple Lines in Each Android ListView Entry

When most people think of a list they think of a single line of text per line. On an Android device a list can have one, two, three and many more lines per list entry. In the article Two Line Lists In Android it was shown how to create a two line entry for each list item. For multiple lines per list entry the same code is used, it is just extended for each additional line. Read the previous article to understand the principles involved. Here we extend that article’s code to add another, third, line to each list entry.

Define the Data

Again the data used is the name of an Amercian State and the state Capital, plus the state population from the 2010 census. The array containing this data is now defined thus:

[code lang=”Java”]private String[][] States_Capitals_Population =
{"Arkansas","Little Rock","2,915,918"},

Define the View for Each List Entry

The file my_two_lines.xml now becomes multi_lines.xml, with a new TextView with id line_c to hold the state population, for example: Continue reading