简体   繁体   English

在ListActivity中使用包含大量行的SimpleCursorAdapter

[英]Use SimpleCursorAdapter in ListActivity with lots of rows

I am developing my first Android app. 我正在开发我的第一个Android应用程序。 I have a ListActivity which uses the SimpleCursorAdapter() to populate the list with a custom layout. 我有一个ListActivity ,它使用SimpleCursorAdapter()用自定义布局填充列表。 What is an efficient way to load the list when the number of rows becomes very large? 当行数变得非常大时,加载列表的有效方法是什么?

As I'm new to Android, I'm not sure what's going on behind the scenes. 由于我是Android的新手,我不确定幕后会发生什么。 Say my result set returns 500 rows--will the ListActivity only render those that are in the visible area or will it try to render all 500? 假设我的结果集返回500行 - ListActivity只会呈现可见区域中的那些还是会尝试渲染所有500行?

Should I instead implement ListView.OnScrollListener to only load say, 25 rows at a time? 我应该实现ListView.OnScrollListener只加载说,一次25行吗? Is there some sort of built-in pagination mechanism that I haven't stumbled upon yet? 有没有某种内置的分页机制,我还没有偶然发现?

Don't worry about efficiency in terms of the size of the data set, as the system will make the necessary optimisations. 不要担心数据集大小的效率,因为系统将进行必要的优化。 Where you can instead make things smoother is the loading of the cursor: make sure you're using LoaderManager with a CursorLoader , as using the SimpleCursorAdapter constructor is now deprecated, since it resulted in cursor queries being run on the UI thread (see this ). 你可以在哪里使事情变得更加平滑是光标的加载:确保你正在使用带有CursorLoader的 LoaderManager ,因为现在不推荐使用SimpleCursorAdapter构造函数,因为它导致在UI线程上运行游标查询(参见本文 ) 。

我想你需要使用视图持有者模式重用ListView行,查看本教程http://www.vogella.de/articles/AndroidListView/article.html

Android will create and destroy each View in the ListView as it sees fit, you shouldn't need to worry about it. Android会根据需要创建并销毁ListView中的每个View,您不必担心它。 Like Chunhui said, the ViewHolder pattern will also help improve the frame rate of the ListView if it feels sluggish. 就像Chunhui说的那样,ViewHolder模式也有助于提高ListView的帧率,如果它感觉迟钝的话。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM