I’ve been searching for a solution to this issue for a few days now.
I’m trying to create a custom ListView list item that can be selectable for mass editing. This would be something similar to the Gmail application that lists the email in your inbox and allows you to select a set of them for an action (delete, move, etc.).
My requirements are:
- Must have a customized look. The android.R.layout.simple_list_item_[checked|multiple_choice] layouts are not suited to what i’m looking for
- I would like it to work with the given ListView#setChoiceMode and ListView#getCheckedItemPositions. Neither is the CheckedTextView. (An alternative approach to this would be fine)
- I would like to make the checkboxes appear when user selects an “edit mode”
- I would like to modify the menu options available similar to Android’s Selection Mode
I’ve tried to add my own checkbox to my view and set an OnClickListener for it to mark the list items as selected/unselected, but that is not quite working for me.
Any help is appreciated; even if it only gets me 90% of the way there.
Please keep in mind that I’m trying to get this to work on Android versions 2.1 and up.
Thank you
So I believe I have resolved the main problem I was facing.
I believe the problem I was having was that my view was not representing the state of the ListView. In lamens; I thought a checkbox was needed to set whether a list item was checked or not (this is the web developer in me). However, the ListView maintains its own state of whats checked and whats not, regardless if you have a view (CheckBox) to represent that or not.
layout/list_item.xml
menu/menu.xml
menu/edit.xml
ListViewTestActivity.java
To have the checkbox reflect the actual selected mode of the list item:
That’s it. Kind of obvious once you know how it all works. Too bad it took me this long to figure out. Sometimes I feel the android programming is a bit too complex at times.
The only problem I have now is that the ListView items are always redrawn when a list item is clicked. This is wreaking havoc on my list items which contain asynchronously loaded images from file. Hopefully when I beef up the performance on that portion of my code, this will disappear.