是否可以在没有 sql 连接的情况下创建活动文件夹? (安卓API)
我一直在阅读 http://developer.android.com/resources/articles /live-folders.html 和 http://developer.android.com/reference/android/provider/LiveFolders .html 和 https://android.googlesource.com/platform/packages/apps/Contacts/+/donut-release/src/com/android/contacts/ContactsLiveFolders.java
但我想扩展我的应用程序(这是一个列表视图)到活动文件夹。这将是一个很好的选择。如何使用列表适配器作为光标?这可能吗?除此之外,我如何设置我的 Listadapter 提供的类似 getView ?是一个 Baseadapter,我的 listadapter 继承它,能够成为 livefolder 需要的光标?
I've been reading http://developer.android.com/resources/articles/live-folders.html
and http://developer.android.com/reference/android/provider/LiveFolders.html
and https://android.googlesource.com/platform/packages/apps/Contacts/+/donut-release/src/com/android/contacts/ContactsLiveFolders.java
But I want to extend my app (Which is a listview) to a live folder. It would be a nice fit. How do i use my listadapter as a cursor? Is this possible? And past that, how do i set the similar getView that my Listadapter provides? is a Baseadapter, which my listadapter inherits, able to become a cursor, which a livefolder needs?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
是的,这是可能的。但你需要一个ContentProvider。虽然 ContentProvider 通常由某些 SQL 数据库支持,但这不是必需的。您可以从任何来源获取 ContentProvider 的 query() 方法中的数据,只要将其作为游标返回即可。如果您没有数据库游标,则可以将数据包装在 MatrixCursor 中并返回 MatrixCursor。
我有这样一个 query() 方法的实现,它通过返回 MatrixCursor 来工作。
ContentProvider 需要由数据库查询支持是一个常见的误解。
最好将 ContentProvider 理解为一个契约,它指定了 4 种不同的 (CRUD) 方法,这些方法采用某些类型的参数并返回某些类型。
此外,您可以在这 4 种方法中进行不同的查询,并根据 Uri 进行切换。
像这样使用 ContentProvider 可以使用任何数据源并在该数据源上执行任何操作,只要您遵守 ContentProvider 类指定的约定。这使得他们极其强大。
Yes, this is possible. But you need a ContentProvider. While a ContentProvider is usually backed by some sql database, it is not an requirement. You can get the data in the ContentProvider's query() method from any source, as long as you return it as cursor. If you dont have a database cursor, you can wrap your data in a MatrixCursor instead and return the MatrixCursor.
I have such an implementation of the query() method and it works by returning a MatrixCursor.
It is a common misunderstanding that ContentProvider need to be backed up by datebase queries.
It is better to understand the ContentProvider as a contract which specifies 4 different (CRUD) methods which take certain types of arguments and return certain types.
Additionally, you can have different queries inside these 4 methods and switch them depending on the Uri.
Used like that ContentProviders can use any datasource and perforn any operation on that datasource, as long as you adhere to the contract specifiied by the ContentProvider class. That makes them extremely powerful.