Category: C #, Android, VS2015;
Date Created: 2016-02-18 I. INTRODUCTION
List view (ListView) is the most frequently used UI component in an Android application, from a list of ubiquitous short menu options to a lengthy contact or Internet favorites list ... will use it to achieve.
The usage of the ListView control is flexible, either by using the built-in view to render the basic style, or by using custom views to render a variety of special visual effects.
To fully master the use of the ListView control provided by Android, you need to address the following issues:
(1) How to render each item in the list view with the Android built-in view
(2) How to implement different adapter classes.
(3) How to render the appearance of each item in a list view with a custom view.
(4) How to read the SQLite database populate list items.
(5) ListView Performance Optimization and the impact of the activity life cycle on the ListView.
The ListView control requires an adapter (Adapter) to describe the view format for each row. In Android apps, you can either use the Android built-in adapter directly or create a custom adapter.
In fact, in the previous chapters, we have used the ListView several times, but this chapter introduces it systematically to its basic usage.
1. ListView Related Classes
Each row in the ListView has its own view. The view may be a built-in view (built-in views) defined in Android.resources, or you can customize the view. Each row can use the same view or a different view.
is the main class to use when rendering a ListView, it is a good idea to take a closer look at the inheritance relationships between classes before learning the contents of this chapter:
(1) ListView
A UI element that renders a series of scrollable list items. On your phone, if you want the list items to occupy the entire screen, you can have the active page inherit directly from the Listactivity class instead of inheriting from the activity class. If you don't want these list items to occupy your entire screen, you can add one or more ListView to the layout page to render.
(2) View
The ListView context requires that each row must provide a view, which can be any UI element.
2. ListView Adapter Class
The meanings and applications of these view adapters are listed below.
(1) Baseadapter class
Baseadapter is the base class for all adapters, which implements the basic functionality of binding a ListView to a data source. When the content of an element in a view is dynamic or not predetermined, it can be implemented using a class that inherits from Baseadapter.
(2) Baseadapter<t> class--most commonly used
In real-world projects, many times applications typically have their own business entity classes, rather than just a collection of strings. In order to extend these capabilities, the custom adapter is implemented in most cases with classes that inherit from Baseadapter<t>.
Implementing a custom adapter with a class that inherits from Baseadapter<t> is the recommended implementation.
(3) Arrayadapter class
In addition to the Baseadapter class, the Android system has a built-in Arrayadapter class. However, when writing an android program in C #, it is rarely implemented.
(4) Arrayadapter<t> class
For multi-column data items, in addition to being implemented by inheriting from the Baseadapter<t> class, you can also render with a custom inherited generic class that inherits from Arrayadapter<t>, but this usage is not seen much in C # programming, The most commonly used or inherited from the Baseadapter<t> class to implement.
(5) Listactivity class
The Listactivity class is built into the Android system, and in the active page it is possible to have custom activities inherit from Listactivit instead of inheriting from the activity, which does not require a custom layout and is suitable for simpler situations.
Listactivity automatically creates a list view and exposes a ListAdapter property that allows the extension class to render a row view with this property. Second, this chapter sample main interface
1. Operation
2, the corresponding code in the MainActivity.cs file
Chitems.add (NewChapter () {Chaptername="9th Chapter List View", Chapteritems=Newchitem[] {NewChitem {type=typeof(Ch0901buildinviewsmain), title="example 9-1 Classification of built-in row views", Desc ="demonstrates how to render various line views built into Android" }, NewChitem {type=typeof(Ch0902main), title="Example 9-2 Custom View", Desc ="demonstrates how to customize a row view" }, }});
"Anroid" 9th Chapter List view (1)--listview related classes and their adapters