开发者

Android ListView, Contacts and Own Data table

Currently I'm pulling out all my contacts and displaying it in a ListView. Next, for each contact in the list I do a check with my own table and display an icon if he is a registered user. So far I have tried the following ways:

1) In开发者_高级运维 the getView() of the adapter, for each row, I call a query on my own table by passing in the contact id. The slows down the scrolling of the ListView and might run into memory issues.

2) In the getView(), for each row, i add the contact id & image view to a queue which does the query 1 by 1 and display the icon. This sorta works but sometimes the display gets weird and randomly shows the icon then disappear.

3) I used a MatrixCursor and tried to join the data but the query in step 1 is called too so it slows down the display again.

Anyone can comment or give a better suggestion would be great! Thanks.


Check Google IO video on listview performance: http://www.youtube.com/watch?v=wDBM6wVEO70

Basically, what you need to do is 2 things:

  1. Implement your own CursorAdapter that holds to your data and attaches it to items as tags. That will speed up scrolling a lot, will look up data only once. Otherwise you hit your table every time item comes into view. Android OS aggresive about disposing items.. This called viewholder pattern, see it discussed here: android listview viewholder. when to use it, and when not to I didn't find better example but you get an idea..

  2. I would cache items from your database into List so you don't have to query for each item.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜