6

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

4

2 回答 2

2

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.

于 2012-12-12T09:23:21.020 回答
0

我想你可以为你的 textView 设置一个标签作为它将从中获取更新的 url。而不是调用“notifyDataSetChanged()”,您可以尝试为该视图使用 findViewByTag(update URL) 和 setText,这样 textview 只会一遍又一遍地重绘而不是整个列表。将充分减少额外重绘的次数。只是一个想法。

于 2011-10-06T08:02:36.250 回答