Simple! .. You cannot find the same control after notifyDataSetChanged(); because this function updates the view with.
public View getView(final int position, View convertView, ViewGroup parent) { return convertView; }
so that you cannot set the flag to the same state, it updates all views.
you need to find the verification status as part of the data using any middleware class.
when you click, you make the data state.
List<CheckState> checkState=new ArrayList<CheckState>();// as an instance holder.checkbox.setOnClickListener(new View.OnClickListener() { public void onClick(View v) { if (((CheckBox) v).isChecked()) { checkState.add(new CheckState(true); } else{ checkState.add(position,false); } }); if(checkState.get(position).isChecked()) { convertView.setBackgroundColor(Color.RED); holder.textView.setBackgroundColor(Color.RED); convertView.invalidate(); } else { convertView.setBackgroundColor(Color.GREEN); }
example: - create an inner class
public class CheckState { boolean isChecked; public CheckState(boolean isChecked) { this.isChecked = isChecked; } public boolean isChecked() { return isChecked; } }
I think this is good for you!
source share