lundi 2 novembre 2015

Android: ListView with Checkbox

I've searched high and low for this issue but am not able to find something concrete.

Basically, I have a list of friends in a ListView and I am trying to create a group by choosing specific friends. To do this I have created an Activity with a SearchView and a ListView. Searching will filter and display friends that I want to add. To do so, I want to use a checkbox. All the "checked" friends will then be passed to another activity where the group creation can be complete.

The activity's layout has a ListView. I have written my own adapter and this adapter inflates the row layout for the ListView. The layout of the adapter has a CheckBox that I have explicitly added.

So activity layout has: ListView Row layout has: TextView and Checkbox

But am having issues with: 1. Trying to keep the checkbox checked when scrolling/searching the listview as the view refreshes and the checkbox is recreated as unchecked - I've solved this for the time being by maintaining a list of the checkboxes clicked. I am doing this in the getView() method of the adapter. 2. Trying to determine which row of the ListView the checkbox belongs to. I'd need this to then create my group of friends. 3. Allowing to edit the list of chosen friends - to add/remove friends before creating the group.

Here is a diagrammatic representation: enter image description here




Aucun commentaire:

Enregistrer un commentaire