How to represent 2 cursors as 1 sorted cursor?

I have two different data sets, each of which uses its own ContentProvider. Answering them, I can get 2 different cursors. These 2 cursors have 2 different primary keys, but there is the same field ( DATE) that I can use for ordering (the other fields are different).

My goal is to have one final merged Cursorthat will be sorted by these fields DATE. I researched MergeCursor, but it doesnโ€™t suit me, since it returns merged / concatenated (but not sorted Cursor).

Any ideas, tips?

+4
source share
1 answer

You can try this class from the 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 entries, that might be fine.

+4
source

Source: https://habr.com/ru/post/1546270/


All Articles