Jan 3 | 3:55 PM |
Mark M. | has entered the room |
Mark M. | turned on guest access |
Jan 3 | 4:15 PM |
Ataul M. | has entered the room |
Ataul M. |
Hi Mark
|
Mark M. |
howdy, Ataul!
|
Mark M. |
how can I help you today?
|
Ataul M. |
I was hoping for a bit of clarification on overriding getView() please :)
|
Ataul M. |
specifically, when it's appropriate to call super.getView(...)
|
Ataul M. |
View paste
|
Mark M. |
you would call super.getView() if you are
extending an existing adapter class (like ArrayAdapter) and you want to
*add* to what the superclass already does, rather than replace it
|
Mark M. |
in your paste, what is "it's" that you want to check for null?
|
Ataul M. |
convertView
|
Ataul M. |
I'm extending SimpleCursorAdapter
|
Mark M. |
if you are extending SimpleCursorAdapter, you don't override getView() at all
|
Ataul M. |
so I just called super.getView without checking for null
|
Mark M. |
you override newView() and/or bindView()
|
Ataul M. |
In my understanding, getview calls newView and/or bindView?
|
Mark M. |
correct
|
Mark M. |
it calls newView() if there is no row ready for recycling
|
Mark M. |
SimpleCursorAdapter, by default, will inflate your selected layout file in newView()
|
Mark M. |
you would override that if you have more complex logic (e.g., different row layouts based upon something in the data)
|
Mark M. |
bindView() is where you pour data into the row, whether that row is newly created or recycled
|
Jan 3 | 4:20 PM |
Mark M. |
SimpleCursorAdapter can do a lot of that for you,
without you overriding bindView(), but you are welcome to override it if
you wish
|
Mark M. |
in neither case do you need to worry about convertView -- you don't even see convertView
|
Ataul M. |
Doesn't getView supply that in one go then? Without having to call them separately?
|
Ataul M. |
them= new/bind
|
Mark M. |
yes, at the cost of writing a lot more code
|
Ataul M. |
ah
|
Mark M. |
and for no gain in speed
|
Ataul M. |
okay got you :)
|
Ataul M. |
another question, related if it's okay
|
Mark M. |
go right ahead -- nobody else is waiting for a turn :-)
|
Ataul M. |
I want to fill a view with data from a contentprovider, so I launch an ASyncTask in my extension of SimpleCursorAdapter
|
Ataul M. |
I cache the results (and check the cache before launching the ASyncTask)
|
Mark M. |
oh, that really doesn't sound good
|
Ataul M. |
:S
|
Mark M. |
an adapter should not be spawning threads IMHO
|
Mark M. |
that's the responsibility of the fragment (or activity if there are no fragments)
|
Ataul M. |
Could I describe my usecase for some advice?
|
Mark M. |
sure
|
Ataul M. |
I'm using SimpleContentProvider to front a SQLite
db, with 1 main table, which I use to populate the adapter using
CursorLoaders.
|
Jan 3 | 4:25 PM |
Ataul M. |
I also need to populate one of the views in a list row, from another table
|
Mark M. |
SimpleContentProvider?
|
Ataul M. |
the mit one: https://github.com/mitmel/SimpleContentProvider
|
Mark M. |
ah, OK, that one
|
Ataul M. |
sorry, 3rd party lib
|
Mark M. |
I know of it but have not used it
|
Ataul M. |
my "another table" can have many records which are related to a single record in my main table
|
Ataul M. |
I was going to use the ASyncTask to get all the related records, and collate the information into a single view
|
Mark M. |
that sounds fine, so long as it is not the adapter starting the task
|
Ataul M. | |
Mark M. |
it's not a question of using AsyncTask instead of a Loader (though you could use another Loader if you wanted)
|
Mark M. |
it's a question of responsibilities
|
Mark M. |
an adapter is solely responsible for rendering rows in a list (or whatever you are using the adapter for)
|
Mark M. |
it's not responsible for data aggregation
|
Mark M. |
any more than a button is responsible for a Web service call, or an EditText is responsible for saving a file
|
Ataul M. |
suppose I did the aggregation in my fragment then,
how might I update the adapter so it renders the currently empty view
(in each row) with the newly aggregated information when it's ready?
|
Mark M. |
when onLoadFinished() is called on your fragment, have the fragment start the AsyncTask
|
Jan 3 | 4:30 PM |
Mark M. |
set the adapter on the list(?) in onPostExecute() of the AsyncTask
|
Mark M. |
if you're saying that you want to display the list
with just the initial Cursor, then augment it with additional data from
the AsyncTask, that's doable but complex
|
Ataul M. |
yes that's exactly what I'm saying
|
Ataul M. |
I have a way, but it'll only update when the views get recycled
|
Mark M. |
you would have to walk the existing child views of
the AdapterView and update them, plus give the adapter the additional
Cursors(?) or whatever the data is for when the user scrolls
|
Ataul M. |
where would I walk through the existing child
views? Presumably I'd only have to do it for the ones that are on
screen? (In my current implementation, or plan, getView() checks to see
if the data is available, and sets nothing if it's not available)
|
Mark M. |
"where would I walk through the existing child views?" -- something triggered by onPostExecute() of the AsyncTask
|
Mark M. |
in terms of who does it... you could argue either the adapter or the fragment
|
Ataul M. |
as in, how could I determine which views are currently displayed?
|
Ataul M. |
*rows
|
Mark M. |
this is a ListView?
|
Ataul M. |
yes
|
Mark M. |
getFirstVisiblePosition() tells you the position index of the first child (getChildAt(0)) of the ListView
|
Jan 3 | 4:35 PM |
Mark M. |
so, you call getChildCount() on the ListView, and
iterate that many times, using getFirstVisiblePosition() as your
position offset, to walk the existing rows
|
Ataul M. |
is there a corresponding getLastVisiblePosition()
|
Ataul M. |
or just do a reasonable amount
|
Mark M. |
there is a getLastVisiblePosition() which you can use
|
Ataul M. |
awesome
|
Ataul M. |
is there a function on campfirenow to email the transcript? I made the mistake of leaving last time without copying it
|
Mark M. |
I post the transcripts shortly after each chat at http://commonsware.com/office-hours
|
Mark M. |
you'll find a couple of years' worth there :-)
|
Ataul M. |
ah brilliant :D
|
Mark M. |
but, no, there's no email-me-a-transcript in Campfire AFAIK
|
Ataul M. |
ok, I think that's enough information for me to get on with for a week ish :)
|
Ataul M. |
Thanks a lot
|
Mark M. |
sure!
|
Ataul M. |
what did you do prior to Android?
|
Ataul M. |
job-wise if you don't mind me asking
|
Mark M. |
that's a bit off-topic for this chat
|
Ataul M. |
fair enough
|
Ataul M. |
thanks again, I'll be back soon no doubt
|
Mark M. |
next chat is tomorrow, 7:30pm Eastern
|
Ataul M. |
I've got them all in my gCal
|
Ataul M. |
:)
|
Mark M. |
ah, OK
|
Ataul M. | has left the room |
Jan 3 | 4:55 PM |
Yurii L. | has entered the room |
Mark M. |
howdy, Yurii!
|
Yurii L. | |
Mark M. |
there's also a chat tomorrow, 7:30pm Eastern, which may fit your schedule better
|
Mark M. |
but, if you have a quick question, go ahead
|
Yurii L. |
is it appropriate to call startActivity in worker thread
|
Yurii L. |
and show dialog while it is starting
|
Yurii L. |
then in handler just dismiss dialog and new activity get's loaded nice and easy
|
Mark M. |
probably not, if I am interpreting you correctly
|
Mark M. |
let's say that you have Activity A and Activity B
|
Mark M. |
Activity A is in the foreground
|
Jan 3 | 5:00 PM |
Mark M. |
Activity A, from a background thread, calls startActivity() to start Activity B
|
Mark M. |
if you are saying that Activity *A* tries to
display a dialog, that will be pointless in most cases, as B will appear
on the screen before the dialog does
|
Mark M. |
(possible exception being if Activity B is in some other app)
|
Mark M. |
now, Activity *B* could elect to display its own
dialog on startup while it does something -- you see this a lot with
ProgressDialog
|
Yurii L. |
yeah but then we need to handle orientation
changes with asynch task and staff and I haven't figure out even if your
book what is the best practice for that
|
Mark M. |
you have to handle that regardless of who starts the dialog
|
Mark M. |
the fact that it is Activity B instead of Activity A does not change that requirement
|
Mark M. |
this is one of the reasons I try to avoid dialogs
|
Yurii L. |
so how do you make show progress while loading anything?
|
Mark M. |
that depends on the rest of the UI
|
Mark M. |
for example, if it's a ListView, use a ProgressBar as the "empty" view in the ListFragment or ListActivity
|
Yurii L. |
awesome, thanks a lot. That is it!
|
Mark M. |
yeah, an in-fragment or in-activity progress indicator tends to be easier than a ProgressDialog
|
Mark M. |
and, that's a wrap for today's chat
|
Jan 3 | 5:05 PM |
Mark M. |
next chat is in ~26.5 hours :-)
|
Mark M. |
have a pleasant day!
|
Yurii L. | has left the room |
Mark M. | turned off guest access |