Office Hours — Today, December 16

Thursday, December 11

Dec 16
7:20 PM
Mark M.
has entered the room
Mark M.
turned on guest access
7:30 PM
Brent
has entered the room
Mark M.
hello, Brent!
how can I help you today?
Brent
Hey Mark.
Couple of questions.
First, drag and drop
I'm trying to use a view that's not in my layout for the dragshadwobuilder
but it doesn't show up
I tried to add it programmatically to the layout, but no go
Mark M.
well, I haven't play with drag-and-drop on Android yet
er, played
Brent
ok
Mark M.
so, I haven't set up a DragShadowBuilder or the like
Brent
let's move to fragments and the back button
ok
let's shift to that other topic then.
i think you'll be able to help
i have a navigation drawer
and some fragments i switch between
i want them to be in the backstack, so that when i hit the back button, i go to the previous one
the problem is that the title and selection in the menu don't properly track
Mark M.
"some fragments I switch between" -- you mean, based upon nav drawer selections?
Brent
the activity title
and when i hit back enough times, i'm left with an empty activity
yes
based on the drawer selections
7:35 PM
Mark M.
I am somewhat skeptical that your desired flow is a good one, but, be that as it may...
are you handling the back stack manually, or via addToBackStack()?
Brent
you mean using the back button as I described? is that the flow you're talking about?
Mark M.
yes
I'd need to look up more on Google
er, Google's nav drawer recommendations
Brent
so you think back should just be allowed to be handled how Android wants it to (i.e., i shoiuldn't override it)
Mark M.
but I don't think the back stack is supposed to survive a jump to another section of your app via the nav drawer
IOW, the back stack should reset if you use the nav drawer to jump to some other spot in the app
but, that's just gut instinct
again, I'd need to look up the recommendations there
Brent
oh. where would the recommendations be?
somewhere in the layout design stuff, i imagine
Mark M.
the classic design guide on this is http://developer.android.com/design/patterns/na...
Brent
ok. i'll look at that.
Mark M.
Material Design probably has its own guidance, though that seems to be more on pure look-and-feel and less on navigation
but, regardless, let's assume for the moment that what you're trying to do is fine, or that you're going to do it regardless of what some balding guy says :-)
are you handling the back stack manually, or via addToBackStack()?
Brent
I'm not following. you mean whatever is written for material design probably only addresses the look, and the older docs are still valid as far as behavior goes?
i tried addToBackStack()
Mark M.
well, Material Design is Google's current "be-all and end-all" on design, so I assume a nav drawer is mentioned there somewhere, but I don't know what it would cover
7:40 PM
Brent
if I don't use it at all, back takes me away from the navigation drawer activity entirely
Mark M.
I'm just mentioning it as another spot of Googly design guidance
Brent
which at this point means back to the home screen of the device
ok
Mark M.
your primary (not mutually-exclusive) options are addToBackStack() or overriding onBackPressed() of the activity
in either case, when the user presses BACK, you'll need to update your nav drawer to match
Brent
yeah, i guess that's where I'm falling down.
Mark M.
in the addToBackStack() path, you would probably register an OnBackStackChangedListener with your FragmentManager
Brent
so there's no example that you know of of what I'm trying to do.
Mark M.
actually, I thought my nav drawer examples had this
been a while since I looked at 'em
(the downsides of having a nearly 3000-page book...)
Brent
i meant to look at yours earlier today, but forgot. i'll check it out.
Mark M.
give me a moment to get one loaded up...
Brent
you have a whole chapter on nav drawer
Mark M.
yes, my NavDrawer/Activated sample that I cover in that chapter uses OnBackStackChangedListener
Brent
great. i'll look that over.
Mark M.
like most of my samples, it's a bit simplified, but it should get you going
7:45 PM
Brent
so do you happen to know what the behavior is when back is pressed in your sample?
is there navigation to earlier selected fragments?
Mark M.
actually, reviewing it, it seems a bit odd
Brent
I see this:
"If the user presses the BACK button, having the earlier fragment reappear happens automatically. However, we need to fix up the navigation drawer to show the proper row as being activated. To do that, we implement OnBackStackChangedListener on MainActivity and call addOnBackStackChangedListener() on the FragmentManager in the onCreate() initialization work. That way, onBackStackChanged() will be called when there is a change in the state of the back stack. Then, it is merely a matter of calling post() for onNavChanged again, to update the nav drawer:"
which seems like what i want
Mark M.
yeah, but my FragmentTransactions do not have addToBackStack()
Brent
huh. so they'r not going on the backstack?
Mark M.
something's out of kilter between the prose and the example
le sigh
Brent
shit happens :)
Mark M.
I'll add this to the list of things I gotta investigate...
Brent
so just so i understand, without the addToBackStack there's no place for a back press to go to, right, at least not to a previously viewed fragment
Mark M.
correct
the rough algorithm is: if there's a transaction on the back stack, roll it back, otherwise finish() the activity
7:50 PM
Brent
makes sense. so if i put the fragment transactions on the backstack and use the listener to help me sync up the menu with what's being shown, i should be able to accomplish what I'm trying to do
Mark M.
yes
Brent
i.e., so your sample, but with transactions added to the backstack, should still be a pretty good guide.
Mark M.
well, I'm less than confident about that at the moment... :-)
Aaron
has entered the room
Mark M.
give me 48-72 hours
I have a book update scheduled, and I'll try to get this cleaned up for that
howdy, Aaron!
Aaron
Hello sir
Mark M.
Aaron: Brent has had a shot at a question, so it's your turn -- do you have a question?
Brent
yeah, I'm good for now, at least
thanks.
Aaron
I have a problem that i have been bangin my head against. If i could maybe get your input on it. Or just some direction that would be great
i have a gist prepared
Mark M.
north by northwest
oh, no, wait, you didn't mean that kind of direction
:-)
Aaron
lol
Brent
not lol ;-)
Aaron
I have shortened the files down because the only related parts have to do with the views
I have a Main activity that has a view pager in it
7:55 PM
Aaron
the view pager holds 4 fragments. One of which is the featured fragment
Featured fragment extends a base fragment that has a Staggered grid view in it
Using etsy staggered grid view
woops i forgot the layouts
I am trying to put a webview fragment into the header of the staggered grid view
It is an AbsListView if i remember right. I have done this with a list fragment but i am getting an view not found error here
Mark M.
ok, that last entry in the chat seemed to take a left turn
what is an AbsListView?
or, more accurately, *what* is an AbsListView? I know what AbsListView is, but I don't understand the relationship to the rest of your issue
and you have done *what* with a ListFragment?
and *where* are you getting a "view not found error"?
Aaron
8:00 PM
Aaron
I have added a header view in a list fragment
using childfragment manager
specifically adding a fragment into the list header
Mark M.
as to whether or not your staggered grid supports header views, you'd have to ask the author of the staggered grid
Aaron
It does.
I have used the header view before to load an image with picasso
Mark M.
as to your error, it seems like the problem is in BaseWebviewFragment
and its relationship to featured_banner_fragment
Aaron
at com.activities.MainActivity.initFragments(MainActivity.java:107)
? where do you see the issue with base webview?
Mark M.
java.lang.IllegalArgumentException: No view found for id 0x7f09009e (staging:id/featured_banner_fragment) for fragment BaseWebviewFragment{42fc9768 #0 id=0x7f09009e}
Aaron
well that fragment is the one i am trying to load into that frame layout
8:05 PM
Aaron
featured_banner_fragment is the framelayout
Mark M.
and that is in R.layout.featured_header?
Aaron
Yes I have added that file to the gist
Mark M.
it feels like Android can't find that widget ID
possibly due to how the staggered grid is implementing the header view stuff
Aaron
hmhm
that is what i was thinking might be my problem
something to do with the lib
Mark M.
stuff like findViewById() relies upon the parents navigating all the children
but that's not automatic
it is up to each ViewGroup implementation
Aaron
Ahh that makes sense is it different if i use findViewByTag?