Android Adapter system

Source: Internet
Author: User

InAndroidOfAPIThe LIST and adapter are both placed in the android. widget package. The specific structure of the package is not displayed here, mainly focusing on the list and adapter. The function of the adapter is to combine the data displayed in the list with the List itself. The list itself only performs display. In fact, it inherits from the VIEWGROUP class. However, another unique function is setAdapter (), which completes the combination of view and adapter. The adapter is actually an adapter. It can encapsulate the data to be displayed in a unified manner, mainly to convert the dataViewProvidedList.

Let's take a look at the Adapter system:

Public interface Adapter ---- layer 0 indicates the hierarchy in the inheritance system)

Public interface ExpandableListAdapter --- (it does not matter because no other interface inherits from it)

This is the ancestor of the adapter. Other personalized adapters implement it and add their own interfaces.

Public interface ListAdapter ---- Layer 1

Public interface SpinnerAdapter ---- Layer 1

Public interface WrapperListAdapter ---- ListAdapter at Layer 2)

The above interface level system has been completed. It can be seen that there are only two types of bridge adapters used as widgetview: ListAdapter, SpinnerAdapter, and ExpandableListAdapter. That is to say, all widgets are based on the list, spinne, and ExpandableList views.

In actual use, we need to add the data to the Adapter, but the adapter presented in the form of an interface cannot save the data, so the Adapter is transformed into a class mode.

Public abstract class BaseAdapter ---- ListAdapter and SpinnerAdapter are implemented at Layer 2)

The top-level abstraction in the type state is constructed in the form of abstract classes, including List and Spinner.

Public class ArrayAdapter ---- Layer 3

Public class SimpleAdapter --- Layer 3

Public class CursorAdapter ---- three-layer CursorAdapter, which has a subclass. We will not discuss it here)

After the basic system is available, let's look at the methods in the top-layer Adapter (only list commonly used methods ):

 
 
  1. abstract Object getItem(int position)  
  2. abstract int getCount()  
  3. abstract long getItemId(int position)  
  4. abstract int getItemViewType(int position)  
  5. abstract View getView(int position,View convertVeiw,ViewGroup parent) 

The above is an important method. ArrayAdapter also implements the above method again. In the actual development process, we often need to make our own Adapter. The above methods need to be implemented again. This can be seen in the APIdemo example provided by android.

Android Adapter system

Android smartphone operating system

Explanation of Android development instances: IMF

Official documentation: Performance Design for running Android apps

Related Article

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.