[Anroid] Chapter 1 List View (1) -- ListView related classes and their adapters, anroid -- listview
Category: C #, Android, VS2015;
Date created: 1. Introduction
List View (ListView) is the most frequently used UI component in Android applications, from the list of ubiquitous short menu options to the lengthy contact or internet Favorites list ...... It will be used for implementation.
The usage of the ListView control is very flexible. You can either use the built-in view to present the basic style or use a custom view to present a variety of special visual effects.
To fully understand the usage of the ListView control provided by Android, you need to solve the following problems:
(1) how to use the built-in Android view to present each item in the List View
(2) how to implement different adapter classes.
(3) how to use a custom view to display the appearance of each item in the List View.
(4) how to read the SQLite database fill list items.
(5) Effects of ListView performance optimization and activity lifecycle on ListView.
The ListView control requires an Adapter to describe the view format of each row. In Android applications, you can directly use the Android built-in adapter or create a custom adapter.
In fact, in the previous chapter, we have used ListView for many times, but this chapter introduces its basic usage systematically.
1. ListView-related classes
Each row in the ListView has its own View. This View may be a built-in View (built-in views) defined in Android. Resources, or a custom View. You can use the same View or different View for each row.
It is the main class used to present the ListView. Before learning the content of this chapter, you 'd better take a closer look at the inheritance relationships between classes:
(1) ListView
UI element, used to present a series of scrolling list items. On a mobile phone, if you want the list items to occupy the entire screen, you can make the Activity page inherit from the ListActivity class instead of the Activity class. If you do not want these list items to occupy the entire screen, you can add one or more ListView entries to the layout page for rendering.
(2) View
The ListView context requires that each row must provide a View, which can be any UI element.
2. ListView adapter class
The following lists the meanings of these view adapters and their application scenarios.
(1) BaseAdapter class
BaseAdapter is the base class of all adapters, which provides the basic function of binding ListView to a data source. When the element content in the view is dynamic or not determined in advance, it can be implemented using a class inherited from BaseAdapter.
(2) BaseAdapter <T> class -- the most common
In actual projects, applications generally have their own business entity classes, not just a collection of strings. To extend these functions, you can use the class inherited from BaseAdapter <T> to implement custom adapters.
It is recommended to use the class inherited from BaseAdapter <T> to implement the custom adapter.
(3) ArrayAdapter class
In addition to the BaseAdapter class, the android system also has the ArrayAdapter class. However, Android programs written in C # are rarely used.
(4) ArrayAdapter <T> class
For multi-column data items, in addition to using the inherited from BaseAdapter <T> class, you can also use a custom inherited from ArrayAdapter <T> generic class for presentation. However, this method is rare in C # programming. The most common method is to use the class inherited from BaseAdapter <T>.
(5) ListActivity class
Android has a built-in ListActivity class. On the Activity page, you can also allow custom activities to inherit from ListActivit rather than the Activity. In this way, you do not need to customize the layout, applicable to relatively simple scenarios.
ListActivity automatically creates a list view and exposes a ListAdapter attribute. The extended class uses this attribute to display the row view. Ii. Main Interface of this Chapter
1. Run
2. The code in the MainActivity. cs File
ChItems. add (new Chapter () {ChapterName = "Chapter 9th List View", ChapterItems = new ChItem [] {new ChItem {type = typeof (ch0901BuildInViewsMain ), title = "Example 9-1 Built-in row view Classification", Desc = "demonstrate how to present various Android built-in row views"}, new ChItem {type = typeof (ch0902Main ), title = "Example 9-2 custom View", Desc = "demonstrate how to customize the row view "},}});