How to close an ActionMode menu programmatically on Honeycomb?

kaneda picture kaneda · Jun 22, 2012 · Viewed 15.5k times · Source

In my application there is a ListFragment where each item from the list contains a checkbox. Whenever the user clicks on one of those checkboxes the app starts an ActionMode context menu. But I want the application to close the ActionMode menu when clicking on another component. I tried Fragment#closeContextMenu() without success.

Any ideas how can I accomplish that?

Answer

Vipul picture Vipul · Jun 22, 2012

Whenever you are creating/starting ActionMode Create by

mMode = startActionMode(....);

To Dismiss it use following Syntax

if (mMode != null) 
 {
     mMode.finish();
 }