Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

MultiChoiceMode before API 11

i implement the ActionMode in my Android App with ActionBarSherlock. With ABS it is possible to build a ActionMode before API 11 but the easy way with: listView.setMultiChoiceModeListener( new MultiChoiceModeListener() ... is not for app before API 11. Has anybody a good way to build a Action Mode Context Menu before API 11? I want to make a long click on a List Item and start the ActionMode in which i can click multiple items. On a simple click i show a detail site of the list item. I use the registerForContext() method but this make a simple and long click.

Has anybody a good tip for me.

EDIT
The solution for my question was following: On a long item click i active the action mode and save this in a variable. In the on item click method i implement a if-else statement with:

if( actionMode == null )
{
   // open new activity or update second fragment
   showDetails( itemPosition );
}
else
{
   // update ui or close CAB if no item selected
   showCAB( itemPosition );
}

The method showCAB( position ) update the selectedItem count, highlight item background and so on.

like image 361
Happo Avatar asked Jul 21 '12 08:07

Happo


2 Answers

Alright, I just did that today, thanks to that site : http://www.miximum.fr/tutos/849-porting-the-contextual-anction-mode-for-pre-honeycomb-android-apps

Basically, you just need to set your ListView ChoiceMode to ListView.CHOICE_MODE_MULTIPLE, to set a onItemClickListener that would check what items are checked on the ListView and to create a private class implementing ActionMode.Callback that will manage the contextual ActionBar.

I let you go on that blogpost to see everything detailed, and some piece of codes !

like image 114
MagicMicky Avatar answered Oct 22 '22 07:10

MagicMicky


You can also have a look at the Google I/O 2012 App. It's opensource, and uses ActionBarSherlock. They have developed a compatibility version of ActionMode related classes that work fine with ABS and on pre-honeycomb devices.

In particular, Take a look at:

  • SessionsFragment class : It shows usage of the compatibility version of ActionMode
  • util.actionmodecompat package: It contains the compatibility ActionMode classes

Basically, just like ABS, their use native implementation of ActionMode when it is available and fallback to the custom implementation on older devices.

Hope it helps!

like image 38
tinesoft Avatar answered Oct 22 '22 09:10

tinesoft