Office Hours — Today, December 7

Wednesday, November 24

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!
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
(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
it's for music
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
8:20 PM
Julius
oh right
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)
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?
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
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
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
8:25 PM
Mark M.
or, C could have the same number of rows as A, but have extra columns obtained from B
or, C could have the same number of rows as B, but have extra columns obtained from A
Julius
oh I see
they'll have different numbers of rows
(almost every time)
Mark M.
OK
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
er columns
yes
Mark M.
then you cannot have Cursor C
well, OK
you could do a SQL-ish full outer join or something
why do you want them in one Cursor? isn't the goal to have them in one ListView?
can't you achieve that by two CursorAdapters, concatenated via a MergeAdapter?
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
basically, assemble the 2D array yourself
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
depends on how many mp3 files a person has
Mark M.
that might be tolerable
8:30 PM
Mark M.
you'd have to try it with a MatrixCursor
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 :)
(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)
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.
See you again soon :)
Mark M.
see ya!
Julius
has left the room
8:55 PM
Mark M.
turned off guest access

Wednesday, November 24

 

Office Hours

People in this transcript

  • Julius
  • Mark Murphy