i have a listview with an imageview and a checkbox. Now the issue here is that when i check the first checkbox, and the i scroll down the list, other checkboxes are also getting checked.
For example, if i check the first check box, then the 5th checkbox is also getting checked and so on. Now i have done something in my getView, such that this error is removing, but when i scroll, then again it becomes unchecked.
Here is my getView()
method
positionArray = new ArrayList<Boolean>(rowItems.size());
for(int i = 0; i < rowItems.size(); i ++)
positionArray.add(false);
//------------------------------------------ the above code is in oncreate
public View getView(final int position, View convertView, ViewGroup parent) {
RowItem rowItem = getItem(position); //List of Items
ViewHolder holder = new ViewHolder();
if (convertView == null) {
LayoutInflater mInflater = (LayoutInflater) context.getSystemService(Activity.LAYOUT_INFLATER_SERVICE);
convertView = mInflater.inflate(R.layout.list_item, null);
holder.imageView = (ImageView) convertView.findViewById(R.id.icon);
holder.radio1 = (CheckBox) convertView.findViewById(R.id.radio);
convertView.setTag(holder);
}
else{
holder = (ViewHolder) convertView.getTag();
}
//holder.radio1.setChecked(positionArray.get(position));
holder.radio1.setOnCheckedChangeListener(new OnCheckedChangeListener() {
@Override
public void onCheckedChanged(CompoundButton arg0, boolean isChecked) {
if(isChecked)
positionArray.set(position, true);
}
});
imageLoader.displayImage(rowItem.getimageUrl(), holder.imageView, options, animateFirstListener);
return convertView;
}