I was reading the new Android Design Standards here: http://developer.android.com/design/patterns/selection.html and was wondering first how to make my ListView selectable (because long presses are now supposed to select items, not show a context menu like before), then to figure out how to pass that information to the ActionBar so I can make a contextual ActionBar based on what is selected (and how many items are selected). I’ve checked out several sites, including http://www.vogella.de/articles/AndroidListView/article.html but it doesn’t show how to do it for ICS with the ActionBar.
I apologize for not giving any code, but I haven’t had to do anything with listviews aside from making custom ones.
For the first part (select list item), you need to do a couple things:
-Depending on the context, set your ListView to either single or multiple choice (depending on your app), using the setChoiceMode method.
-in order to mark the item as selected, just listen for a long press and call the ListView’s setItemChecked method.
Finally, in order for the listview item to show as selected, you need to add the following attribute to the custom XML layout for that listview item:
android:background="?android:attr/activatedBackgroundIndicator"For creating contextual Action Bar, the process is a little more detailed, but it’s outlined in the Android Developer guide in the Using Contextual Action Mode section.