简体   繁体   中英

Use SimpleCursorAdapter in ListActivity with lots of rows

I am developing my first Android app. I have a ListActivity which uses the SimpleCursorAdapter() to populate the list with a custom layout. 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. 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?

Should I instead implement ListView.OnScrollListener to only load say, 25 rows at a time? 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 ).

我想你需要使用视图持有者模式重用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. Like Chunhui said, the ViewHolder pattern will also help improve the frame rate of the ListView if it feels sluggish.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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