Using ListView, GridView, and Adapters

The ListView and GridView are both descendants of ViewGroup, but they are used more like a View since they are data driven. In other words, rather than defining all the possible Views that might fill a ListView (or GridView) at design time, the contents are created dynamically from the data passed to the View. (The layout of the ListItem might be created at design time to control the look of the data during runtime.)

As an example, if you needed to present a list of countries to a user, you could create a LinearLayout and add a button for each country. There are several problems with this approach: determining the countries available, keeping the list of buttons up to date, having enough screen space to fit ...

Get Android Application Development Cookbook - Second Edition now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.