So now in my code I check first and I only create the view from scratch if it's null. Otherwise, I only modify the existing view to change the background color to signify that it has been selected. I also store the two Drawables that are the backgrounds so they don't have to be retrieved and assigned memory for each object. This allows the ListView to refresh quickly as it doesn't have to reacquire the underlying objects and rebuild the entire view based on the object's properties each time the selection is changed. This seems like a simple thing, but maybe someone else that is struggling with ListView performance will happen across my post.
Side projects, and non-profit work. Always in search of the indefinable hack.
Saturday, June 15, 2013
Efficient Custom ListView Adapter Selections
A customer requested I create a ListView of their business objects using custom graphics and text based on the status of the object. I had no problem creating it but they complained that it took too long to refresh when making selections. After puzzling over the code for awhile trying to determine how to speed it up, I realized that the convertView paramter passed in to the GetView method that I was overriding in my custom listview adapter was actually the existing view of the object, and if it wasn't null I didn't have to recreate it.
So now in my code I check first and I only create the view from scratch if it's null. Otherwise, I only modify the existing view to change the background color to signify that it has been selected. I also store the two Drawables that are the backgrounds so they don't have to be retrieved and assigned memory for each object. This allows the ListView to refresh quickly as it doesn't have to reacquire the underlying objects and rebuild the entire view based on the object's properties each time the selection is changed. This seems like a simple thing, but maybe someone else that is struggling with ListView performance will happen across my post.
So now in my code I check first and I only create the view from scratch if it's null. Otherwise, I only modify the existing view to change the background color to signify that it has been selected. I also store the two Drawables that are the backgrounds so they don't have to be retrieved and assigned memory for each object. This allows the ListView to refresh quickly as it doesn't have to reacquire the underlying objects and rebuild the entire view based on the object's properties each time the selection is changed. This seems like a simple thing, but maybe someone else that is struggling with ListView performance will happen across my post.
Labels:
Android,
BaseAdapter,
C#,
convertView,
GetView,
ListView,
ListViewAdapter,
Mono for Android,
Selection,
Xamarin,
Xamarin.Android
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment