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.

Community
  • 1
  • 1
Johnny Doe
  • 3,280
  • 4
  • 29
  • 45
  • 5
    Why should this be a duplicate? – Konsumierer Oct 08 '12 at 14:46
  • 4
    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 : http://stackoverflow.com/questions/11642877/how-to-recognize-whether-the-done-button-is-clicked-in-actionmode) – Flynny75 Dec 10 '12 at 11:23
  • 1
    It looks like this is possible with a normal ActionBar. http://dazcorp.blogspot.com/2013/04/edit-mode-and-why-using-contextual.html – Jonah Jan 01 '14 at 04:10
  • You do it with a normal ActionBar, a custom view, and this layout code for the button itself (from stock Contacts app): https://github.com/android/platform_packages_apps_contacts/blob/master/res/layout/editor_custom_action_bar.xml – Jonah Jan 01 '14 at 04:55
  • http://stackoverflow.com/questions/11725729/prevent-to-cancel-action-mode-by-press-back-button this question has answer to what you are facing. – pellucide May 31 '14 at 04:26

1 Answers1

-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

Rémi F
  • 1,327
  • 12
  • 25
  • 2
    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. – Johnny Doe Oct 03 '12 at 13:49
  • 1
    Could you post a bit of code in order to help you? (and also xml) – Rémi F Oct 03 '12 at 17:28
  • 8
    Really this is the accepted answer? You have to be kidding me. – jfcartier Aug 29 '14 at 16:48