Principle of ListView and RecyclerView of Android

There are four components in using ListView or its better version RecyclerView:

  1. Adapter extended from android.support.v7.widget.RecyclerView.Adapter.
  2. ViewHolder extended from RecyclerView.ViewHolder
  3. Layout for each item.
  4. View model.

The adapter links a list to the instances of ViewHolder (via onBindViewHolder) each of which corresponds to an item and inflates the layout that displays the item.  Each view model corresponds to an item, and is passed to a ViewHolder by the adapter via onBindViewHolder.

 

This article was updated on 20:57:17 2024-07-11