Maisonobe.A (MaaKs) wrote:
> here is an issue that drives me crazy :
> 
> I have a simple class that extends list activity , for each contact i
> have in my phone
> it adds a line to the list containing two checkboxes .
> It seems to work  but when you check for example the first checkbox ,
> and then you scroll the list down
> , some other contacts will be checked too like they are linked the one
> to the others.
> I simplified the code to the extrem minimum and i still have the same
> bug . here is the code , if someone know how to deal with that it
> would be really nice i spend half the day to try to find a solution to
> that .

You are not holding onto the checkbox states anywhere.

Rows in a ListView usually get recycled, meaning that when you scroll,
Android does not create a brand-new row, but rather updates an existing
row with new data. Since you are not doing anything to manage the
contents of your checkboxes, Android is ignoring them, giving you the
random checked effect you are seeing.

If you are going to put stateful widgets in list rows, like checkboxes
or RatingBar, you need to track those values and set/reset them yourself.

Here is an excerpt from _The Busy Coder's Guide to Android Development_
that covers this, though bear in mind that it uses RatingBar where you
will need to use checkboxes:

http://commonsware.com/Android/excerpt.pdf

-- 
Mark Murphy (a Commons Guy)
http://commonsware.com | http://twitter.com/commonsguy

_The Busy Coder's Guide to *Advanced* Android Development_
Version 0.9 Available!

--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google
Groups "Android Developers" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to