0

On my Listview have checkbox on each item. And on ListItemClick event i did like this

I want that when click on the Listview item, the checkbox will be checked and if the checkbox hv been checked then un-check them. It's worked fine with the small list (less than 10 items).

public void onListItemClick(ListView parent, View v, int position, long id)
{           
    position = position -  parent.getFirstVisiblePosition() ;
    CheckBox cb = (CheckBox) parent.getChildAt(position).findViewById(R.id.checkBox);
    if (cb.isChecked())
    {
        cb.setChecked(false);   
    }
    else            
    {
        cb.setChecked(true);    
    }
}

And the problem is when the Listview have around 50 items. When i click on the first item then a scroll down a bit the other item also checked. Something like item at position 10, 20 have been auto checked.

Anybody know how come the other item is auto-checked and how to fix it, tks

AdrDev_CTS
  • 245
  • 4
  • 11
  • Are you using a custom `Adapter`? If so, please post the code for it as well. – kaspermoerch Nov 22 '11 at 09:11
  • Refer this [link][1]... [1]: http://stackoverflow.com/q/7966789/874752 – Ramesh Akula Nov 22 '11 at 09:14
  • Checkout my answer [here](http://stackoverflow.com/questions/7738527/getting-an-issue-while-checking-the-dynamically-generated-checkbox-through-list/7738854#7738854) and also the complete thread to get exactly what is happening here. Knickedi has explained awesomely below my answer. – Lalit Poptani Nov 22 '11 at 09:14
  • is it on the getView() we just add the checkbox control to the ViewHolder – AdrDev_CTS Nov 22 '11 at 09:48

0 Answers0