0

I have a custom search actionMode and I want to catch the OK (tick) button press to execute the search. The tick button doesn't seem to call onActionItemPressed(..).

What is the best way to capture the tick press?

// this is what I have:
@Override
        public boolean onActionItemClicked(ActionMode mode, MenuItem item) {
            switch (item.getItemId()) {
                default:// ok button
                    if (search) applySearch();
                    stopActionMode();
                    okPressed=true;
                    KeyBoardUtil.hideKeyboard(SlideTabbedActivity.this, filterText);
            }
            return true;
        } 
siliconeagle
  • 7,379
  • 3
  • 29
  • 41
  • This question is answered here: http://stackoverflow.com/questions/11642877/how-to-recognize-whether-the-done-button-is-clicked-in-actionmode/14090730#14090730 – intrepidis Jun 06 '13 at 17:03

1 Answers1

1

In fact, you should add a new MenuItem instead of using DONE to perform the search. Clicking DONE is equal to pressing back, and onDestroyActionMode() will be invoked.

Sahil Mahajan Mj
  • 11,033
  • 8
  • 53
  • 100
faylon
  • 7,360
  • 1
  • 30
  • 28
  • That really doesn't fit with the function logically - when they press the tick it should search as it is a confirmation - it should be a cancel icon at least. What is the best way to override it? – siliconeagle Dec 15 '12 at 13:48
  • OK not i understand i put this in the destroy and override the back to escape the search – siliconeagle Dec 15 '12 at 13:50
  • The contextual action bar is used to perform actions on multi items, when you select several rows, you can delete them, save them or do any action else, at last you pressed the DONE, to exit the action mode. It is the normal process. You can try to look into some native android apps with action mode. – faylon Dec 15 '12 at 14:37