Office Hours — Today, January 30

Thursday, January 25

Jan 30
8:55 AM
Mark M.
has entered the room
Mark M.
turned on guest access
ck
has entered the room
Mark M.
hello, ck!
how can I help you today?
ck
Hi Mark
View paste
I have an Activity that contains a viewpager that hosts two fragments - FragmentA and FragmentB. The two fragments both have their own toolbars. 

The host activity overrides onOptionsItemSelected() but it's triggered only when FragmentB's up back button is clicked. But when FragmentA's up back button is clicked, it's not triggered.
9:00 AM
Mark M.
if I had to guess, the last call to make the toolbar be the action bar wins
ck
hmmmm.... so that's FragmentB then.
Mark M.
right
ck
How can I make both work instead.
Mark M.
I doubt that is possible
an activity only has one action bar
either there should only be one Toolbar (outside of the pager, presumably), or each fragment would need to manage the up affordance itself
ck
I want each fragment to manage the up button.
do I think need to still override the activity onOptionItemsSelected() for that?
Mark M.
probably not
use setNavigationOnClickListener() on the Toolbar, I guess
9:05 AM
ck
Ok, I will try that!
Mark M.
each fragment would have its own listener for its own Toolbar's navigation clicks
ck
Thanks.
ok
I still have to call setHasOptionsMenu() right?
Mark M.
only if you are trying to use it as an action bar
you could just use setOnMenuItemClickListener() on the Toolbar
ck
ok
9:15 AM
ck
Hi Mark, how will I make the arrow button show up on the toolbar in the Fragment?
Mark M.
setNavigationIcon(), I presume
ck
should I still call the setDisplayHOmeAsUpEnabled()?
Mark M.
no, that's an action bar thing
ck
ok.
Mark M.
basically, if it isn't a method on Toolbar, but you think it might affect the toolbar, it's an action bar thing
and that only works if the Toolbar is set to be the activity's action bar
which only works if you only have one Toolbar that will serve in that role
and in your case, you have two
9:20 AM
ck
If I want to set a listener when the custom navigation icon is clicked on the toolbar, is it setNavigationOnClickListener or setOnMenuItemClickListener()?
Mark M.
I believe that is setNavigationOnClickListener()
setOnMenuItemClickListener() would be for the items added via inflateMenu()
9:25 AM
ck
Inside the onClick() how can I know the if my custom icon was clicked
Mark M.
I do not understand
there is only one navigation button
ck
yea
ok
Mark M.
there is a dedicated listener for it, set via setNavigationOnClickListener()
ck
I get it now!
alright!
thanks!
I have no more questions
Mark M.
you're welcome!
ok
ck
has left the room
9:55 AM
Mark M.
turned off guest access

Thursday, January 25

 

Office Hours

People in this transcript

  • ck
  • Mark Murphy