Optimizing the ListView
In order to make scrolling through out lists as smooth as possible, we need to ensure that the construction and manipulation of the items run as fast and as efficiently as possible.
How to do it...
One way in which we can optimize the list items is to reuse the item view:
This is very easy to do, and all we need is to check is whether we can use the
convertView
parameter before trying to create a new instance of the item:if (convertView == null) { var inflater = LayoutInflater.From(context); convertView = inflater.Inflate( Resource.Layout.ListItemLayout, parent, false); } var firstRow = convertView.FindViewById<TextView>( Resource.Id.firstRow); firstRow.Text = person.Name;
Another way is to store references to the various subviews so that we don't have look for them each time, as follows:
Create a type that will hold a reference to those subviews:
private class ViewHolder : Java.Lang.Object { public ImageView Icon; public TextView FirstRow; public...