Principle of ListView and RecyclerView of Android
There are four components in using ListView or its better version RecyclerView:
- Adapter extended from android.support.v7.widget.RecyclerView.Adapter.
- ViewHolder extended from RecyclerView.ViewHolder
- Layout for each item.
- 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.