{"id":723,"date":"2019-11-24T12:32:01","date_gmt":"2019-11-24T02:32:01","guid":{"rendered":"https:\/\/learntodroid.com\/?p=723"},"modified":"2019-11-24T12:32:07","modified_gmt":"2019-11-24T02:32:07","slug":"what-are-the-differences-between-recyclerview-and-listview","status":"publish","type":"post","link":"http:\/\/10.0.0.14:32769\/what-are-the-differences-between-recyclerview-and-listview\/","title":{"rendered":"What are the differences between RecyclerView and ListView?"},"content":{"rendered":"\n

If you ever need to show a scrollable list of items in your app you might consider using a RecyclerView or ListView to achieve this. In this article I will summarise the major differences between RecyclerView and ListView in Android.<\/p>\n\n\n\n

The key differences between the RecyclerView and ListView in Android are documented in the table below.<\/p>\n\n\n\n

Criteria<\/th>RecyclerView<\/th>ListView<\/th><\/tr><\/thead>
Requires additional dependency<\/td>Yes, RecyclerView requires an additional dependency<\/td>No, available natively<\/td><\/tr>
ViewHolder Pattern<\/td>Mandatory ViewHolder pattern providing better performance<\/td>ViewHolder pattern can be supported with customisation<\/td><\/tr>
Layout Management<\/td>Advanced Layout Management capabilities for vertical and horizontal lists, grids and staggered grids<\/td>Vertical list only<\/td><\/tr>
Adapters<\/td>Supports notifications if the entire data set has changed, item gets added, item gets removed or item gets changed<\/td>Supports notifications if the entire data set has changed<\/td><\/tr>
Item Decorations<\/td>Dividers between items not shown by default. Use ItemDecorations to add margin and draw on or under an Item View. <\/td>Dividers between items shown by default. Item decoration requires customisation for ListView.<\/td><\/tr>
Item Animation<\/td>ItemAnimator makes it easy to add animations<\/td>Very complex to implement<\/td><\/tr>
Official Documentation<\/td>RecyclerView documentation<\/a><\/td>ListView documentation<\/a><\/td><\/tr><\/tbody><\/table><\/figure>\n\n\n\n

In the sections below I will describe in the greater detail the functionality available in RecyclerView and ListView APIs. In the Conclusion section I will summarise the key differences between RecyclerView and ListView and in describe in what circumstances each should be used.<\/p>\n\n\n\n

What is a RecyclerView?<\/h2>\n\n\n\n

A RecyclerView is used to display a large list of items with their own specific Views within the user interface in a performance optimised manner.<\/p>\n\n\n\n

\"\"
RecyclerView Component Architecture
Credits:
RecyclerView ins and outs – Google I\/O 2016<\/a><\/figcaption><\/figure>\n\n\n\n

LayoutManager<\/h3>\n\n\n\n

The RecyclerView uses a LayoutManager to determine how the Views will be placed within the RecyclerView. The different LayoutManagers supported by RecyclerView include:<\/p>\n\n\n\n