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!
|
Mark M. |
how can I help you today?
|
ck |
Hi Mark
|
ck |
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.
|
Jan 30 |
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
|
Mark M. |
an activity only has one action bar
|
Mark M. |
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.
|
ck |
do I think need to still override the activity onOptionItemsSelected() for that?
|
Mark M. |
probably not
|
Mark M. |
use setNavigationOnClickListener() on the Toolbar, I guess
|
Jan 30 |
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.
|
ck |
ok
|
ck |
I still have to call setHasOptionsMenu() right?
|
Mark M. |
only if you are trying to use it as an action bar
|
Mark M. |
you could just use setOnMenuItemClickListener() on the Toolbar
|
ck |
ok
|
Jan 30 |
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
|
Mark M. |
and that only works if the Toolbar is set to be the activity's action bar
|
Mark M. |
which only works if you only have one Toolbar that will serve in that role
|
Mark M. |
and in your case, you have two
|
Jan 30 |
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()
|
Mark M. |
setOnMenuItemClickListener() would be for the items added via inflateMenu()
|
Jan 30 |
9:25 AM |
ck |
Inside the onClick() how can I know the if my custom icon was clicked
|
Mark M. |
I do not understand
|
Mark M. |
there is only one navigation button
|
ck |
yea
|
ck |
ok
|
Mark M. |
there is a dedicated listener for it, set via setNavigationOnClickListener()
|
ck |
I get it now!
|
ck |
alright!
|
ck |
thanks!
|
ck |
I have no more questions
|
Mark M. |
you're welcome!
|
Mark M. |
ok
|
ck |
has left the room |
Jan 30 |
9:55 AM |
Mark M. |
turned off guest access |