

We define one menu item which is used to delete items from ListView. This file defines menu items for contextual action bar. Ĭreate a new context_main.xml in res/menu folder and copy the following content. Ĭreate a new activity_main.xml in res/menu folder and copy the following content. Open res/values/styles.xml and replace it with following content. Ĭreate a new strings_menu.xml in res/values/ folder and copy the following content. Open res/values/strings.xml and replace it with following content. Include ActionBarSherlock as a library project. OutputĬreate an Android project and name it as CABDemo. Here, contextual action bar has delete menu item, which deletes the selected items from ListView. In this tutorial we’ll see how to use Contextual Action Bar for ListView using ActionBarSherlock library where list items can be selected on long press gesture. This tutorial explains the second method.

The user selects a checkbox or similar UI component within the view.You can invoke contextual action mode based on one of the two events or both. But it doesn’t support the native ListView integration, so you need to control CAB’s lifecycle by yourself. It has its own contextual action bar implementation, which is easy to set up. If your app works on android version 2.x and higher the best approach is to use ActionBarSherlock library.

Although it is available from Android 3.0 it is a good practice to use it in apps working on earlier API versions.If you’re using Android 3.0 or higher there is a detailed description of CAB setup on each selection method – whether contextual action should be performed on a single selected item or on a group of selected items.Implementing CAB for ListView item selection The action mode is disabled and the contextual action bar disappears when the user deselects all items, presses the BACK button, or selects the checkmark button on the left side of the bar. It is recommended to use when you perform actions with selected data like plain text or data items from ListView or GridView components. Select additional data items by touching them. It appears after the user long presses on a selectable data item. The selection CAB is a temporary action bar that overlays your app’s current action bar while data is selected. 4.7 Create Android Custom Adapter class for ListView.2 Implementing CAB for ListView item selection.
