The Latest

List Display Comparison for Android

Wednesday, January 20, 2016

Hello,

My name is Raymond, and I'm a BlackCitrus Engineer. Today, I am going to compare the different views for displaying a list, and when to use each of these. These are:

  • ScrollView
  • ListView (with BaseAdapter)
  • ListView (with MergeAdapter)
  • RecyclerView (with RecyclerAdapter)

So why is list display so important in Android? This is because apps usually have to display a data set and a list view is effective in doing so. Furthermore, it is important to choose the right list view, as some of the problem for choosing an incorrect view may result in:

  • You rewriting a lot of code to cater for client's change request. (code maintence)
  • Affecting the performance of your app if you want to show complex 3D type of data set. (Performance)

1. ScrollView

This is the most simplest display for data set in Android. You simply put your content inside the <ScrollView></ScrollView> tags and it is done. The advantage of using a ScrollView is that it is very quick to implement. However it is not optimise for speed so you should not have a lot of item in it. My recommendation is that if you have 20+ child views inside a ScrollView, you should consider using a ListView or a RecyclerView.

When to use it?

  • When the widgets you are displaying are overflowing out of the screen, but your view may not be a list.
  • For static set of data, such as settings options, the fields from a sign up form, etc.

When not to use it?

  • Do not use it if you need display a lot of data (Eg: 20+ item).
  • If your view contains static items, but it is going to be very long, ideally you should separate it into another screen (such as a Fragment or an Activity).
  • Do not use it if your data is going to be dynamic. For example, if your data set fits any of keywords of 'Categories', 'Medias', 'Images', 'Videos', 'Dates', 'Months', 'Years', that's a hint that you should use another view instead.

For more info, look at: http://developer.android.com/reference/android/widget/ScrollView.html

2. ListView (with BaseAdapter)

This view is the most effective in displaying a dynamic data set. However, it involve more coding to get the work done. The use of BaseAdapter is efficient in displaying data set, because it re-use its views to draw to the screen quickly. Suppose your screen only fits 6 item view, but you have 100 items. These 6 item view will be swapped around in an infinite loop on the screen. Depending on where your scroll index is, a subset of item is fetched from the list of 100 items, which is then populated into the 6 reused views.

When to use it?

  • When you are displaying a dynamic data set. If your data set only have 2 items, but it will still be dynamic, you should use it.
  • When you are not able to use a RecyclerView to do what you want.

When not to use it?

  • Do not use it for display displaying static data, such as a sign up form, or to display settings options. If you decide to use a list view on a sign up form, you will find that you will need to write more code to make sure user input does not suddenly disappear from their textfields.
  • If your data set is too complex, and it involve you writing a lot of code to get the work done, consider using a ListView (with MergeAdapter).
  • If you are only displaying 1 item.

For more info, look at:

http://developer.android.com/reference/android/widget/BaseAdapter.html

3. ListView (with MergeAdapter)

Sometimes, the client or the designer may ask you to display a list on the app, but each item would have a header to categorise it. Or, they may ask you to merge to completely different data set into one view. Or they may even ask you to have a normal page/screen, with a list at the bottom, but the whole thing should scroll as one. Whatever the request, it is often possible with a MergeAdapter. Please note that MergeAdapter is not a native Android library, but an OpenSource library written by a group called "CommonsWare"

When to use it?

  • Your data is dynamic.
  • When the data you want to display cannot be achieved by a ListView (with BaseAdapter)

When not to use it?

  • When there's a more simple solution to get the job done.

For more information, look at:

https://github.com/commonsguy/cwac-merge

4. RecyclerView (with RecyclerAdapter)

This is the latest library written by Android for displaying a list of data. It's usage is similar to a ListView, but it is more efficient. The performance is more obvious if you are using a very slow phone or a complex view such as a 3D scrolling view. The reason it is so fast is because underneath its implementation, it implements the holder's pattern. This means better re-use of views. However, since this is a new library, there is lack of support from the online community to customise its usage. Therefore at times, you may need to fallback to the usage of ListView.

Another good thing with this library is that it can be used to display data in a grid and horizontally very easily. Whereas ListView was limited to a single vertical list (with horizontal support if using an open source library). 

When to use it?

  • When you are showing dynamic data.
  • For display a list of data, that needs to be optimised with speed.

When not to use it?

  • When you are unable to show what you want, then you may consider falling back to a ListView (with MergeAdapter).

For more information, look at:
http://developer.android.com/reference/android/support/v7/widget/RecyclerView.html