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 ):
- abstract Object getItem(int position)
- abstract int getCount()
- abstract long getItemId(int position)
- abstract int getItemViewType(int position)
- 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