I figured this out also.  Chalk it up to me being a total rookie with
gui programming.  The issue is that the list items get reused and I
was calling setChecked from within my bindView code *before* setting
the OnCheckedChangeListener.  During startup it doesn't really matter
because the list items are all being created for the first time and
there are no registered listeners.  However on subsequent rebindings,
the old listener is still associated with the view and when I call
setChecked... all hell breaks loose.  So the key was simply to set the
callback before calling setChecked.  Also I was calling setChecked
within the callback and calling notifyDataSetChanged which were just
causing more iterations through this loop and more craziness.  Anyway,
here is the working code:


                        // We need to be sure and register the new 
OnCheckedChangeListener
before
                        // we call setChecked because these views get reused 
and there
might still
                        // be old callbacks associated with previous alarm 
"item"s which
causes very
                        // f-ed up behavior. (I know)
                        CheckBox enabledCheckBox = 
(CheckBox)alarmView.findViewById
(R.id.itemEnabledCheckBox);
                        enabledCheckBox.setOnCheckedChangeListener(new
OnCheckedChangeListener() {
                                public void onCheckedChanged(CompoundButton 
buttonView, boolean
isChecked) {
                                        item.setEnabled(isChecked);
                                        dbAdapter.updateAlarm(item.getId(), 
item);
                                }
                        });
                        enabledCheckBox.setChecked(enabled);

On Jul 25, 11:46 am, eags <eagsala...@gmail.com> wrote:
> The only problem is there is a strange bug with the CheckBox that I
> can't figure out.  Even though bindView works correctly to get the
> information from each alarm and fill out the different pieces of my
> inflated list item view, it doesn't work for the checkbox.  The
> behavior is really really strange where it seems like the same
> OnCheckedChangedListener object is being associated with several
> different list items.
>
> What I see is that if I change the enabled state by either clicking on
> the CheckBox or by opening the edit dialog and changing the state
> there, the state is changed for several of the different items
> simultaneously.  Sometimes several will change at once but the one I
> checked *doesn't* change.  I really don't get what is going on here.
> I wonder if the ListView has some special behavior with regard to
> CheckBoxes that I'm not aware of that I am messing up because I don't
> know about it.
>
> Anyway, if anyone has any insight into this problem and could throw me
> a clue that would be very helpful as I'm totally confused myself.
>
> Thanks.
>
> On Jul 24, 10:23 am, Gregg Reno <gregg.r...@gmail.com> wrote:
>
>
>
> > Excellent!  Thanks for posting this eags.  From all of the postings
> > I've seen from people looking to do something similar, this should be
> > a big help.
>
> > Just started working through this to adapt it to my project, but I'm
> > getting a bunch of syntax errors.  I should probably start a project
> > from scratch and get this one working first.
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google
Groups "Android Developers" group.
To post to this group, send email to android-developers@googlegroups.com
To unsubscribe from this group, send email to
android-developers-unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to