What's the role of adapters in Android?

前端 未结 10 1171
面向向阳花
面向向阳花 2020-12-02 04:10

I want to know when, where and how adapters are used in the context of Android.

The information from Android\'s developer documentation wa

相关标签:
10条回答
  • 2020-12-02 04:31

    Well adapters in Android are basically a bridge between the UI components and the data source that fill data into the UI Component

    For example, Lists (UI Component) get populated by using a list adapter, from a data source array.

    0 讨论(0)
  • 2020-12-02 04:33

    I would like to share my understanding.

    It's an interface between the data source and your layout (most probably ListView).

    An analogy

    Let's take the example of a mobile charger, or rather a USB cable. The wire can be considered as the adapter, while the data source and layout can be understood as the socket (plug-in point) and USB port (charging point) respectively.

    In the case of mobile charging, the source of the power may be different, e.g. charging from a power bank, a socket or a laptop. The same is the case for the adapters used in Android. The data source may be changed depending upon the application requirement.

    In short, an adapter in Android carries the data from a source (e.g. ArrayList<>) and delivers it to a layout (.xml file).

    0 讨论(0)
  • 2020-12-02 04:33

    Adapters are basically used to deliver content. One adapter you probably have in every application is the CursorAdapter which enables you to deliver content given by a cursor from a database query. A ListView has nearly always some sort of Adapter.

    0 讨论(0)
  • 2020-12-02 04:33

    Adapter is simply used to achieve the listview concept. Not only for displaying the list of data but also the some custom view. Suppose customer wants to use the list which has more number of textview (any other view) then , we have to use Adapter view in Android.

    0 讨论(0)
  • 2020-12-02 04:40

    Adapters in Android are a bridge between the adapter view (e.g. ListView) and the underlying data for that view. Imagine what the world would have been without adapters!

    Examples

    • A view that shows items in a vertically scrolling list. The items come from the ListAdapter associated with this view.

    • The ListAdapter defines the layout for individual rows of the list and provides data to the ListView via the setAdapter() method of ListView.

    • Android provides several standard adapters; the most important are ArrayAdapter and CursorAdapter.

    • ArrayAdapter can handle data based on arrays or lists.

    • SimpleCursorAdapter can handle database related data.
    0 讨论(0)
  • 2020-12-02 04:48

    An adapter manages the data model and adapts it to the individual rows in the list view. It extends the BaseAdapter class.

    Every line in the list view consists of a layout which can be as complex as you want. A typical line in a list view has an image on the left side and two text lines in the middle.

    0 讨论(0)
提交回复
热议问题