[英]Android: Populate ListView directly from SQLite Database - without using ArrayList
Is it possible to populate a ListView from a SQLite Database without saving the data to an Array or List first? 是否可以从SQLite数据库填充ListView而无需先将数据保存到Array或List? I have about 20000 lines of data in my SQLite Database. 我的SQLite数据库中大约有20000行数据。
Thanks! 谢谢!
You can use CursorAdapter to achieve this. 您可以使用CursorAdapter来实现。 Here goes a tutorial: http://www.mysamplecode.com/2012/07/android-listview-cursoradapter-sqlite.html 这是一个教程: http : //www.mysamplecode.com/2012/07/android-listview-cursoradapter-sqlite.html
Yes. 是。 This is possible. 这个有可能。 Use a SimpleCursorAdapter
to populate your ListView
directly from a database. 使用SimpleCursorAdapter
直接从数据库填充ListView
。 To avoid performing database operations on the UI thread ( startManagingCursor
and stopManagingCursor
), it is recommended to use a CursorLoader
- backed by a ContentProvider
- in order to load data asynchronously. 为了避免在UI线程( startManagingCursor
和stopManagingCursor
)上执行数据库操作,建议使用由ContentProvider
支持的CursorLoader
以便异步加载数据。 Read more... http://developer.android.com/guide/components/loaders.html https://developer.android.com/training/load-data-background/setup-loader.html 了解更多... http://developer.android.com/guide/components/loaders.html https://developer.android.com/training/load-data-background/setup-loader.html
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.