Detailed explanation and sample code of listview and GridView developed by Android
Listview and GridView are common controls in Android development. They can achieve many interface effects when used with adapter. The following illustrates the usage of listview and GridView with examples.
1. Android development example of listview
Listview is one of the most commonly used controls in Android development. Generally, the list consists of three elements. Listview: the view used to display the list, adapter: the bridge between data and view, and data: specific data includes strings, pictures or controls.
Adapters are generally of the following types:
Arrayadapter: one of the simplest adapters in Android, dedicated to list controls. Only one row of data is displayed.
Simpleadapter: this adapter has the best extensibility and can customize various effects. Lists are often populated with static data.
Cursoradapter: provides data to the list through a cursor.
Resourcecursoradapter: this adapter extends cursoradapter and knows how to create views from resources.
Simplecursoradapter: this adapter extends the resourcecursoradapter to create a textview / ImageView view from the columns in the cursor. Here's an example of getting an address book:
XML / HTML code
Java code
2. Android development example of GridView
GridView a grid view that displays multiple rows and columns. Direct example:
XML / HTML code
Java code
After reading these two Android development examples, I believe you have a certain grasp of the use of listview and GridView. You can also use them and adapters to achieve more functions.
The above is the data sorting of Android listview and GridView. We will continue to supplement relevant data in the future. Thank you for your support for this site!