One, the need to build a ListView condition has
- Data source: Can be read from the database, network crawl, etc., belongs to the M layer in MVC
- The layout file for the ListView sub-item, which belongs to the V layer in MVC
- Adapters: For connecting data sources and layouts, belong to the C layer in MVC
Second, the solution steps, first on the final effect:
1, solve the M layer, that is, the data source, because it is just a string, so directly in the code listing the list item string:
1 Private void createlist () {2 New String[] {"A", "B", "C", "D", "E", "F", "G", "H", "I",3 "J", "K", "L", "M", "N", "O", "P", "Q", "R" "S", "T", "U",4 "V", "w", "X", "Y", "Z" }; 5 }
2, solve the V layer, that is, the ListView child layout file, this example is very simple, direct use of Android comes with the style of Android. R.LAYOUT.SIMPLE_LIST_ITEM1:
1 New Arrayadapter<string>(2 ListViewStyle1. this listItems);
3, solve the C layer, that is, the adapter:
1 New Arrayadapter<string>(2 ListViewStyle1. this listItems); 4 This . Findviewbyid (r.id.lvstyle1); 5 Lvstyle1.setadapter (adapter);
"Android first line code" learning record 009-listview simple usage