0

I have a GridView using a custom adapter which consists of a relativelayout containing an imageview. I have enabled MultiChoiceMode on the gridview and enabled CAB (Contextual Action Bar). This works great, however I am stumped on how I will show a persistent selector around my grid items as they are selected. My selector works on the initial press, but I have yet to find a way in which it will persist until the item is unselected.

Expectation: User long presses an item, the item is selected and the application enters CAB mode. As each item is pressed a purple frame (as defined by my selector statement in the XML) will appear around each object until they are unselected.

Result: User long presses an item, the item is briefly showing the selector, it disappears, and user gets no visual feedback to selecting or unselecting items, even though it's registered in code.

I have tried every single selector event but none seems to handle this. Any workarounds? Anything I'm missing?

An example of what I am trying to achieve is presented by trying to long press an item in the Android 4.0 or 4.1 Gallery application

---> API 15 <---

Michal Kordas
  • 10,475
  • 7
  • 58
  • 103
Lexious
  • 13
  • 1
  • 10

1 Answers1

1

Try modifying the layout for your list items to have a different background attribute:

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@+id/listItemRelativeLayout" 
    android:layout_width="fill_parent" 
    android:layout_height="match_parent"
    android:background="?android:attr/activatedBackgroundIndicator">

    ...

</RelativeLayout>

That Android attribute references a selector that's used when you call listView.setItemChecked(int index, boolean checked), and for some reason it seems to work this way.

Also, verify that you call this on the list view:

listView.setChoiceMode(AbsListView.CHOICE_MODE_MULTIPLE);
afollestad
  • 2,929
  • 5
  • 30
  • 44
  • Worked excellently! Retrieved the ressource element from android source and modified it to use purple, and now its exactly how i want. Thank you sir! – Lexious Jul 31 '12 at 16:34