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.
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 !
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:
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!
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With