Mark M. | has entered the room |
Mark M. | turned on guest access |
Dec 7 | 8:15 PM |
Julius | has entered the room |
Julius |
hi Mark
|
Mark M. |
howdy, Julius!
|
Mark M. |
how can I help you today?
|
Julius |
I have a question, but expected it to be busy and have to compose it
|
Mark M. |
nope, pretty quiet
|
Julius |
I was wondering if it's possible to combine the reults of two Cursors
|
Mark M. |
define "combine"
|
Julius |
I have a list and it will get data from two places: 1. a ContentProvider and 2. a SQLiteDatabase
|
Julius |
(At the moment the only thing I can think of is to
copy all the data from the ContentProvider's db to my db which seems
wrong! :))
|
Mark M. |
meaning that you want a single ListView containing one Cursor's data, followed by the other Cursor's data?
|
Julius |
well I was hoping to combine both
|
Julius |
it's for music
|
Julius |
so I have good meta data in my db for some music
|
Mark M. |
again, I need you to define "combine"
|
Julius |
and I have the meta data for the music on the device itself which varies in quality depending on how it was encoded
|
Dec 7 | 8:20 PM |
Julius |
oh right
|
Julius |
uh ok so I have a list of say songs and usually I
would create a query and get a Cursor and supply an ordered cursor to
the adapter (for the list)
|
Julius |
so now I would like to have a Cursor which is populated with data from both sources
|
Mark M. |
and what will you do with the Cursor?
|
Mark M. |
and when you say "populated with data from both sources", is this an append operation, a SQL-style JOIN, or something else?
|
Julius |
supply it to a CursorAdapter which will be set for the ListActivity (eg.)
|
Mark M. |
and when you say "populated with data from both sources", is this an append operation, a SQL-style JOIN, or something else?
|
Julius |
that's the question really, I'm not sure how to combine the data from the two different dources
|
Julius |
sources
|
Mark M. |
OK, this is frustrating, so hang on while I try to explain
|
Julius |
(sorry!)
|
Mark M. |
let's say you have Cursor A and Cursor B
|
Mark M. |
and you are aiming for a "combined" Cursor C
|
Julius |
yes
|
Mark M. |
there are probably millions of possible ways to "combine" A and B to get C
|
Julius |
oh I didn't realise that
|
Mark M. |
for example, C could be the data from A, followed by the data from B, assuming they both have the same column layout
|
Dec 7 | 8:25 PM |
Mark M. |
or, C could have the same number of rows as A, but have extra columns obtained from B
|
Mark M. |
or, C could have the same number of rows as B, but have extra columns obtained from A
|
Julius |
oh I see
|
Julius |
they'll have different numbers of rows
|
Julius |
(almost every time)
|
Mark M. |
OK
|
Mark M. |
is Cursor C then the combination of A's rows and B's rows?
|
Julius |
and the columns could be different too - but they should share some attributes
|
Julius |
er columns
|
Julius |
yes
|
Mark M. |
then you cannot have Cursor C
|
Mark M. |
well, OK
|
Mark M. |
you could do a SQL-ish full outer join or something
|
Mark M. |
why do you want them in one Cursor? isn't the goal to have them in one ListView?
|
Mark M. |
can't you achieve that by two CursorAdapters, concatenated via a MergeAdapter?
|
Mark M. | |
Julius |
I figured with the Cursor I could manipulate the
combined dataset more easily so I coul then say order the combination by
title or create date
|
Mark M. |
well, you'd have to build a MatrixCursor
|
Mark M. |
basically, assemble the 2D array yourself
|
Mark M. |
that will be slow and memory intensive for lots of rows, though
|
Julius |
ah ok MergeAdapter looks like it might e the way to go
|
Mark M. |
how much data are you anticipating?
|
Julius |
hundreds
|
Julius |
depends on how many mp3 files a person has
|
Mark M. |
that might be tolerable
|
Dec 7 | 8:30 PM |
Mark M. |
you'd have to try it with a MatrixCursor
|
Mark M. |
of course, you could also just assemble the stuff into POJOs and use an ArrayAdapter, then
|
Julius |
I'll take a look at those two options thank you - apologies for not being clearer :)
|
Julius |
(it wouldn't be a problem if I didn't need to sort the combination I coul just tack the result of one onto the other)
|
Dec 7 | 8:35 PM |
Julius |
Looking forward to reading any updates of your books (and sections I haven't yet read) at the beach after christmas.
|
Julius |
See you again soon :)
|
Mark M. |
see ya!
|
Julius | has left the room |
Dec 7 | 8:55 PM |
Mark M. | turned off guest access |