Apr 11 | 7:25 PM |
Mark M. | has entered the room |
Mark M. | turned on guest access |
Apr 11 | 7:30 PM |
Brett G. | has entered the room |
Mark M. |
howdy, Brett!
|
Mark M. |
how can I help you today?
|
Brett G. |
Hi Mark!
|
Brett G. |
First, thanks for the Awesome book! I really appreciate how fresh you keep it!
|
Mark M. |
you are very welcome
|
Brett G. |
I have a follow up from a question you answered for me on SO this week: http://stackoverflow.com/questions/15907664/how...
|
Mark M. |
I have it up now
|
Mark M. |
what you want is very reminiscent of the EU4You example
|
Brett G. |
I'm implementing this single activity app with individual fragments for each screen.
|
Mark M. |
OK
|
Brett G. |
I'm using your loaderex
|
Mark M. |
SQLiteCursorLoader?
|
Apr 11 | 7:35 PM |
Brett G. |
and I'm a having some trouble figuring out how to run the loader from within a fragment, instead of from within an activity
|
Brett G. |
yes sir
|
Mark M. |
first, what is your android:minSdkVersion?
|
Brett G. |
grabbing some code from my remote desktop now
|
Mark M. |
(IOW, are you using the fragment backport, or regular API Level 11 fragments?)
|
Brett G. |
support library, absherlock
|
Brett G. |
and you're loaderex library
|
Mark M. |
OK
|
Mark M. |
getLoaderManager() is available on Fragment
|
Mark M. |
so, pretty much it should work just like it does on an activity
|
Brett G. |
oh wow, I bet that's my prob. I was calling getSherlockActivity and accessing from the Activity
|
Mark M. |
except that you probably implelement the LoaderCallbacks<Cursor> on the fragment
|
Brett G. |
was having trouble with back/forward navigation with that setup
|
Mark M. |
I'm not convinced that working with LoaderManager
directly in the fragment (vs. getting it from the activity) will help in
that regard
|
Mark M. |
what specific trouble were you encountering?
|
Brett G. |
I see getLoaderManager, but not getSupportLoaderManager
|
Brett G. |
in the SherlockFragment
|
Mark M. |
getLoaderManager() on the support.v4 Fragment returns a support.v4 LoaderManager
|
Mark M. |
hence, there is no dedicated getSupportLoaderManager()
|
Brett G. |
OK, I'll change it out now and see if that fixes
my problem, here's a code snippet of what I'm doing in case you see
something. It works fine on first load, but if I hit back and the come
back to the fragment again, the changeCursor call doesn't have any
effect
|
Apr 11 | 7:40 PM |
Brett G. |
View paste
|
Brett G. |
View paste
(8 more lines)
|
Mark M. |
you want to use swapCursor() with Loaders
|
Mark M. |
use the CursorAdapter backport if needed: http://developer.android.com/reference/android/...
|
Brett G. |
OK, I'll change that out. I did try that a few
minutes ago and I'm still having the trouble with the listview not
loading after swapping the cursor
|
Mark M. |
beyond that, I am not quite certain what is happening to your fragment mix when you press BACK
|
Mark M. |
are you using addToBackStack() to handle that, or are you doing something manually (and, if so, what)?
|
Brett G. |
Yes, I'm using FragmentTransactions as your recommended and adding to back stack
|
Blake M. | has entered the room |
Brett G. |
and I just popbackstack if the home/up button is pressed
|
Mark M. |
(BTW, howdy, Blake -- be with you shortly!)
|
Blake M. |
Hi ya'll. New to commonsware, so I thought I'd just stop by and say hello
|
Mark M. |
OK, and then how are you "returning" to the fragment?
|
Mark M. |
are you saying that you are holding onto the Fragment instance somewhere yourself?
|
Brett G. |
just press the button that "transacts" to it again
|
Apr 11 | 7:45 PM |
Mark M. |
or are you creating a new fragment each time the user taps on the list entry?
|
Apr 11 | 7:45 PM |
Brett G. |
Here's the onclick code:
|
Brett G. |
getSherlockActivity().getSupportFragmentManager().beginTransaction().addToBackStack(null).setCustomAnimations(R.layout.slide_in_right,R.layout.slide_out_left,
android.R.anim.slide_in_left,android.R.anim.slide_out_right).replace(R.id.frameRight,
new FragMyVerses(), "FragMyVerses").commit();
|
Mark M. |
right, so you are creating a new fragment each time
|
Brett G. |
Yes
|
Mark M. |
you would wind up with a new ListView each time regardless, as onCreateView() should be called fresh again anyway
|
Brett G. |
I would be fine with that.
|
Mark M. |
assuming that the loaders are handing you an
actual Cursor with actual data, I do not know why the contents would not
appear after swapCursor()
|
Brett G. |
the cursor has data if I put a breakpoint there
|
Brett G. |
but after swapping, the listview is empty
|
Brett G. |
only on subsequent loads of the fragment, it works fine on the first load
|
Mark M. |
I do not know what would be causing that
|
Brett G. |
trying it now with getLoader from fragment instead of activity to see if that helps
|
Mark M. |
double-check to make sure the CursorAdapter is holding the right Cursor post-swap
|
Mark M. |
and perhaps poke around in Hierarchy View to see if it is a rendering issue, more than an adapter issue
|
Mark M. |
meanwhile, let me take a question from Blake, and I'll be back with you shortly
|
Mark M. |
Blake: howdy, sir -- do you have a question?
|
Blake M. |
Hi Mark. No question, really. Just stopped by to see how this works.
|
Mark M. |
ah, OK
|
Mark M. |
it's mostly for Q&A, more than a "hangout" type chat, though you are welcome to stick around if you like
|
Mark M. |
attendance varies from zero to a half-dozen
|
Apr 11 | 7:50 PM |
Blake M. |
ah! ok, fair enough.
|
Mark M. |
I try to take everyone's questions in turn, so I don't get lost in a bunch of parallel chat threads
|
Blake M. |
hey, actually, do you happen to know what a Theme
really is? A style, of course, and visible where android Styles are
not. But how does it work?
|
Mark M. |
themes aren't my strong suit
|
Blake M. |
me too. ok then, see you around.
|
Mark M. |
my interpretation of a theme is: a style that is
applied to a whole activity/app, and that can affect things beyond an
individual widget (e.g., window behavior, like whether there is an
action bar)
|
Mark M. |
someday, I need to spend quality time on the subject and add an Advanced Styles and Themes chapter to my book :-)
|
Blake M. |
yeah. I think so. ... and you can "back-fit" values into it, I think.
|
Blake M. |
:-)
|
Blake M. | has left the room |
Mark M. |
OK, Brett: do you have another question?
|
Apr 11 | 7:55 PM |
Brett G. |
thanks for your patience, i'm trying to test the change over a slow remote desktop connection
|
Mark M. |
no worries, chime in if another question comes to mind
|
Brett G. |
is the first code sample I pasted the correct way
to initialize the loader, checking for null and the either initLoader or
forceLoad?
|
Mark M. |
in your case, probably
|
Brett G. |
[and then either initLoader or forceLoad?]
|
Mark M. |
I haven't experimented with your scenario
|
Mark M. |
to be honest, I'm not a Loader fan
|
Brett G. |
I had to change it to that method to get it to reload properly on 'back' navigation to the fragment
|
Brett G. |
would you just use asynctask?
|
Mark M. |
yes, or something along those lines
|
Apr 11 | 8:00 PM |
Brett G. |
what would I be looking for in the call hierarchy?
|
Mark M. |
I am sorry, but I do not understand your question
|
Brett G. |
you mentioned looking for a rendering issue there
|
Mark M. |
not call hierarchy, Hierarchy View
|
Mark M. |
lets you inspect the widgets and containers of your running activity in an emulator
|
Mark M. |
basically, confirm that the ListView truly is empty
|
Mark M. |
i.e., has no children
|
Brett G. |
sounds like something helpful I need to familiarize myself with
|
Mark M. |
it's a perspective in Eclipse, or available from the standalone monitor tool if you are not using Eclipse
|
Mark M. |
I have coverage of it in the book
|
Mark M. |
and there is http://developer.android.com/tools/debugging/de...
|
Brett G. |
sweet, loading it up now
|
Apr 11 | 8:05 PM |
Brett G. |
I'm setting setRetainInstance(true); on all of my fragments, is that appropriate in my scenario?
|
Brett G. |
for configuration changes
|
Mark M. |
Loaders will redeliver your Cursor to you post-config change
|
Mark M. |
hence, in theory, you should not need setRetainInstance(true) for that
|
Mark M. |
and I seem to recall that Dianne Hackborn was opposed to using setRetainInstance(true) with Loader-based fragments
|
Brett G. |
Gotcha, I saw a post from her today that mentioned that which is why I asked :)
|
Brett G. |
didn't know if it would apply to my situation, so glad to have a confirmation.
|
Brett G. |
But for my fragments without a loader, I'll continue to "setRetainInstance(true);", correct?
|
Mark M. |
only if you need it
|
Apr 11 | 8:10 PM |
Brett G. |
If I don't have that set, and I'm 5 pages
(fragments) into my navigation, won't I lose my place when the activity
reloads? Or is it smart enough to reload my fragment stack?
|
Mark M. |
the back stack is independent of setRetainInstance(true), if that's what you mean
|
Mark M. |
all of your fragments always get recreated on a configuration change (except those that are retained)
|
Brett G. |
hmm, I'll have to go change my code back. I
thought I remembered it landing me back at the first fragment after a
screen rotation
|
Mark M. |
make sure that, on a configuration change, you
don't accidentally force yourself back to the first fragment by running
transactions
|
Brett G. |
ah, gotcha
|
Brett G. |
I think you hit the nail on the head :)
|
Mark M. |
"the nail says, 'ow!'"
|
Mark M. |
:-)
|
Brett G. |
I prob did have the code to check for existence of them in place yet back then
|
Brett G. |
I hadn't ready the Fragments section of your book at that point :)
|
Brett G. |
[read]
|
Apr 11 | 8:15 PM |
Brett G. |
well so much for testing this, I'm all of a sudden
getting the dreaded 'table not found' error on my database query all of
sudden.
|
Mark M. |
that's a little odd
|
Brett G. |
haven't had that problem in days
|
Brett G. |
back when I was setting up my database access singleton
|
Mark M. |
unless you're wiping out internal storage yourself, your database should be around from previous runs
|
Brett G. |
and copying the db to the wrong folder
|
Mark M. |
"copying the db"?
|
Brett G. |
I just fired up an emulator since I'm not in the office
|
Mark M. |
you're shipping a database?
|
Brett G. |
I use a pre-made db, yeah
|
Mark M. |
are you using SQLiteAssetHelper for that?
|
Brett G. |
I have a lot of library data user's can pick from
|
Brett G. |
SQLiteOpenHelper
|
Brett G. |
I'm guessing there's a better way :)
|
Mark M. |
ah, you really want to consider using SQLiteAssetHelper: https://github.com/jgilfelt/android-sqlite-asse...
|
Mark M. |
handles the package-a-database scenario nicely
|
Mark M. |
I cover it in the book as well, with my own sample app
|
Mark M. |
beats rolling your own solution
|
Apr 11 | 8:20 PM |
Brett G. |
I just picked up your book last night, so I plan
to be much more familiar with the basics by our next chat session :)
I've only made it through the fragments and config changes section at
this point
|
Mark M. |
it's a big book
|
Brett G. |
I'm very excited about having everything in one
place, and not having to filter through all of the "old" methods to find
what's current
|
Brett G. |
I really appreciate what you're doing!
|
Mark M. |
pretty much everything was spruced up in a "reboot" of the book a year ago
|
Brett G. |
I'm gonna check out and go help with the little one. Thanks so much for your time and insight!
|
Mark M. |
each update, I try to refresh some existing material in addition to covering new topics
|
Mark M. |
you are very welcome
|
Mark M. |
BTW, these chats are archived at http://commonsware.com/office-hours/
|
Mark M. |
this chat's transcript will show up a few minutes after the chat ends
|
Brett G. |
Good Night! Great! That's helpful to know!
|
Apr 11 | 8:30 PM |
Mark M. |
that's a wrap for today's chat
|
Mark M. |
next chat is Wednesday at 10am Eastern
|
Mark M. |
have a pleasant day!
|
Brett G. | has left the room |
Mark M. | turned off guest access |