Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Listview's ArrayAdapter notifydatasetchanged() very slow redraw

I've a quite simple list with 3 textview fields on each row. We are updating their values every 2 seconds or so with data coming from a background webservice call ( AsyncTask )

We compare the coming values with the current ones, update them accordingly on the Adapter and finally calling notifyDataSetChanged() if needed

The thing is that the redraw gets really slow thus hanging the whole UI when we got more than 3 update rows at once. Of course we are using all ListView well-known optimizations such as the EfficientAdapter approach ( setTag() and holders ), and getViewTypecount()/getItemViewType() . We have also tried to optimize our interface as much as possible with layoutopt and trying to avoid wrap_content widths and heights to lighten things up .

We don't do expensive operations on our updates either, just standard stuff: changing TextView text, textcolor, and backgroundcolor values.

The only weird thing I can see is that getView() is called 3-4-5 times for each row, although I've read all those Romain's messages [1] telling that is nothing wrong with that

Any ideas or hints on how can we speed it up?

Thank you very much!

[1] http://groups.google.com/group/android-developers/browse_thread/thread/4c4aedde22fe4594/aeb04288064f495e?show_docid=aeb04288064f495e

like image 585
Albert Avatar asked Sep 27 '10 16:09

Albert


1 Answers

This is for those browsing from google thinking they need to rewrite their own data changed method. Based on my data, you don't need to for many cases.

notifyDataSetChanged() can be MUCH FASTER than your hand coded replacement and it all depends on your actual listview implementation.

Sample: A simple 3-line text-only listview with max 10K row ArrayList updated via menu selection.

Manual notifyDataSetChange()

--- avg run-time: 4ms

Default free notifyDataSetChange()

--- avg run-time: 0ms <--- you can't get faster than this.

Don't run to create your own replacement unless you time and benchmark your stuff. Use the free stuff until necessary.

like image 127
Diegomontoya Avatar answered Nov 15 '22 09:11

Diegomontoya