How to correctly handle action mode "done" button? [duplicate]
Asked Answered
E

1

24

Possible Duplicate:
How to invoke the ActionBar's ContextMenu-like behavior?
How to recognize whether the Done button is clicked in ActionMode

How to correctly handle action mode "done" button?

Action mode done button

I perform some operations on an object in the action mode and I want to save the result by click on this button - like "save and exit". How can I dispatch key-press on this button?

The only the way I see is to override onDestroyActionMode(ActionMode mode) method with flags, triggered in dispatchKeyEvent(KeyEvent event) to handle if it was caused by "back" button press.

Logcat:

"Done" pressed

10-03 14:31:58.211: D/DESTROY(967): onDestroyActionMode  

"Back" pressed

10-03 14:32:01.771: D/DISPATCH(967):   Action: 0/n  Keykode: 4  
10-03 14:32:01.911: D/DISPATCH(967):   Action: 1/n  Keykode: 4  
10-03 14:32:01.911: D/DESTROY(967): onDestroyActionMode

But it is not look like good practice. Is there any "nice" solution?

UPD: I know how to invoke action mode and handle action item events in ActionMode.Callback, but how i can catch "Done" button press to modify it's behavior? "Back" button and "Done" button both leads to ActionMode.Callback's onDestroyActionMode() call.

Emissivity answered 3/10, 2012 at 11:46 Comment(5)
Why should this be a duplicate?Confrere
This is not a duplicate. There doesnt appear to be possible/easy way to do this, looking at ActionBarSherlock the view containing the done button calls finish directly with no parameters. Modifying ABS is possible, but then it wont work because ABS falls back to native above 3.0. This is stupid oversight by Google. (edit: yeah this is a dupe : #11643377)Chiclayo
It looks like this is possible with a normal ActionBar. dazcorp.blogspot.com/2013/04/…Inferno
You do it with a normal ActionBar, a custom view, and this layout code for the button itself (from stock Contacts app): github.com/android/platform_packages_apps_contacts/blob/master/…Inferno
#11726229 this question has answer to what you are facing.Fireguard
C
-4

This pattern is called CAB (Contextual Action Bar). Please have a look to the Menu guide and search for CAB on the official website : Using the contextual action mode

Confinement answered 3/10, 2012 at 12:58 Comment(3)
Already. But i didn't find enything that can helps me. I think it is not standart application for this component, so this moment may be out of official guide. Upd. Or I just missed something important.Emissivity
Could you post a bit of code in order to help you? (and also xml)Nason
Really this is the accepted answer? You have to be kidding me.Landgraviate

© 2022 - 2024 — McMap. All rights reserved.