Android Learning 4, Android that adapter

Source: Internet
Author: User

I. INTRODUCTION of Adapter

An Adapter object acts as a bridge between an and the AdapterView underlying data for that view. The Adapter provides access to the data items. The Adapter is also responsible for making a for each item in the View data set.

A adapter is a bridge between the Adapterview view and the data, adapter provides access to the data, and is responsible for generating a corresponding view of each data. Its effect is for example with what is seen:


Ii. the inheritance relationship of adapter

There are two adapter systems, such as the following:

1.



2.



Three, the method in adapter

In practical applications. The inheritance system of adapter is more widely used. So. To know something about adapter's approach.

Public interface Adapter {//In order to avoid generating a lot of view wasted memory in Android. The view in the Adapterview is recyclable and is used. For example, if you have 100 data to display, and your screen can only display 10 data at a time, then//Only 10 view will be generated, and when you drag down to display the 11th view, a reference to the 1th view is passed through. Update the data inside the display again, that is, view can be reused. Only the data in the update view is used to display a new//item, if the view type of a view is Ignore_item_view_type, then this view will not be reused static final int ignore_item_view_type = adapterview.item_view_type_ignore;static final int no_selection = integer.min_value;//a observer, When the data represented by adapter is changed, it is notified, and Datasetobserver is an abstract class. Two methods are defined: OnChanged and oninvalidatedvoid Registerdatasetobserver (Datasetobserver observer);//Cancel the registration of a observervoid Unregisterdatasetobserver (Datasetobserver observer);//The number of items represented by the data int getcount ();//Returns the data item at the specified Location object GetItem (int position);//Returns the Idlong getitemid (int position) of the data item at the specified location, or indicates whether the ID of all data items is stable, false is returned by default in Baseadapter, and if it is unstable, In CursorAdapter, the _id in True,cursor is the invariant Boolean hasstableids ();//generate corresponding views for each data item view GetView (int position, view Convertview, ViewGroup parent);//Gets the corresponding position of this figure type int getitemviewtype (int position);//GetView The number of view types that can be returned. (In HeaderviewlistadaThe pter can include headers and footer. GetView can return a view in the header, footer, and adapter//, but its getviewtypecount that implementation is called inside adapter that Getviewtypecount, the neglected header, Footer The view//Type, do not know. int Getviewtypecount ();//Is an empty Boolean isEmpty ();}




Android Learning 4, Android that adapter

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.