Efficient ListView in android

本小妞迷上赌 提交于 2019-11-26 21:42:24

问题


What is the best way of constructing a ListView that uses the least memory possible? This is important, because I met a few implementations and most of them is lagging when I scroll the ListView on low-end devices, but I saw a few apps, where the scroll is very smooth, even on low-end devices. How can it be done? What is the most efficient way from a memory usage point of view to construct such a ListView?


回答1:


  • recycle your views in getView()
  • use ViewHolder pattern
  • use lazy loading if you have a lot of data to fill the list with
  • use Cursor as underlying data instead of object list built from cursor if your data comes from database, you save memory by not creating additional objects.
  • see http://www.google.com/events/io/2010/sessions/world-of-listview-android.html
  • see http://android.amberfog.com/?p=296



回答2:


You will have to use the ViewHolder pattern.




回答3:


Look at this code with description to increase the efficiency of lisview.

Keep in mind when you have lots of data to show in listview then at a time do not load all data . First load 2o data then load another when listview reaches at end.

This is also another way to increase the efficiency of listview.



来源:https://stackoverflow.com/questions/11684520/efficient-listview-in-android

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!