I have a ListView that has 649 entries. Each View in the list has two LinearLayouts, an ImageView, a few TextViews, and a CheckBox. I currently have code to go through all the C
I was also facing a similar king of problem, so after lot of reading I solved this problem like this:
@Override
public View getView(int position, View convertView, ViewGroup parent) {
ViewHolder holder = null;
if (convertView == null) {
convertView = mInflater.inflate(R.layout.listview, null);
holder = new ViewHolder();
holder.nameView = (TextView)convertView.findViewById(R.id.textView1);
holder.numberView = (TextView)convertView.findViewById(R.id.textView2);
holder.cb = (CheckBox)convertView.findViewById(R.id.checkBox1);
convertView.setTag(holder);
} else {
holder = (ViewHolder)convertView.getTag();
}
holder.nameView.setText(mData.get(position).toString());
holder.numberView.setText(mNumber.get(position).toString());
holder.cb.setChecked(false);
holder.cb.setTag(position);
if(selected.indexOf(mNumber.get(position).toString()) >= 0)
{
holder.cb.setChecked(true);
}
return convertView;
}
}
Here what I am doing that on getView() I am unchecking all the checkboxes and checking again manually those which I need to be checked according to the textview it corresponds. So if the user scroll down after checking the first checkbox, all the checkbox in the view will get unchecked and if he again scrolls up then also all the checkboxes will be unchecked but then the one he clicked before will be again rechecked.
Hmmmm I think you misunderstood what the getChildCount()
and getChildAt()
methods do. Those will actually get only the rendered views. Unless I misread something here, if you have 650ish rows you cannot accomplish what you want with the views that are being rendered. Instead, you should implement an onItemClickListener
(or, alternatively, something that fires when the checkboxes are clicked) and after the checkbox is checked, save that state into your model.