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?
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.
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