Asfanur
Asfanur

Reputation: 245

Distinct Query For CursorLoader

I am using CursorLoader to populate my listView. But I need to get distinct result set. But CursorLoader has no constructor to set distinct parameter.

Any Suggestions?

Upvotes: 0

Views: 1537

Answers (1)

G. Blake Meike
G. Blake Meike

Reputation: 6715

Yes!

In the CursorLoader constructor you specify a URI. Part of that URI is the ContentProvider Authority. The rest, though, is up to you! So create a virtual table!

If you have a table "songbirds", perhaps your URI is:

content://my.content.provider/songbirds

Simply teach your ContentProvider (add one more clause to your UriMatcher) to recognize the URI:

content://my.content.provider/distinctSongbirds

Process the "distinct" URI exactly as you do the non-distinct one, except add a "distinct" param to the actual DB query, when you make it.

Upvotes: 1

Related Questions