How to represent 2 cursors as 1 sorted cursor?

て烟熏妆下的殇ゞ 提交于 2019-11-28 08:43:52

问题


I have 2 different sets of data, each of them use its own ContentProvider. Querying to them I can get 2 different cursors. Those 2 cursors has 2 different primary keys, but there's one and the same field (DATE) which I can use for ordering (other fields are different).

My goal is to have one final merged Cursor which will be sorted by those DATE field. I have investigated MergeCursor but it doesn't fit to me, since it returns merged/concatenated (but not sorted Cursor).

Any ideas, clues?


回答1:


You can try this class from AOSP repository: https://android.googlesource.com/platform/frameworks/base.git/+/android-4.4.4_r1/core/java/com/android/internal/database/SortCursor.java

There is a performance warning at the beginning of the class but if you don't have 10K or 100K records it might be fine.



来源:https://stackoverflow.com/questions/24448614/how-to-represent-2-cursors-as-1-sorted-cursor

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