Android Learning Quad, Android adapter

Source: Internet
Author: User

First, the 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 the practical application, the inheritance system of adapter is applied more widely, so we should have some understanding of the adapter method.

Public interface Adapter {//In order to avoid generating a large amount of view wasted memory, in Android, the view in Adapterview is recyclable. For example, if you have 100 data to display, and your screen can only display 10 data at a time, then//Just create 10 view, when you drag down to display the 11th view, the 1th view will pass the reference, update the data inside the display, that is, the 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 notified of changes, Datasetobserver is an abstract class that defines two methods: 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 position, 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 not stable, the _id in True,cursor is returned in CursorAdapter as a constant Boolean hasstableids (); Generate corresponding views for each data item view GetView (int position, view Convertview, viewgroup parent);//obtain the corresponding position of this figure type int getitemviewtype (int position);//GetView The number of view types that can be returned. (In HeaderviewlistadaPter can include headers and footer,getview to return to the headers, footer, and adapter//views. But the implementation of its getviewtypecount is only called the internal adapter Getviewtypecount, ignoring the header, footer in the view//Type, do not understand. int Getviewtypecount ();//Is Empty Boolean isEmpty ();}




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.