I have a list view which contains an item name and checkbox in front of the item name, and one delete button below the layout, if my list contains 15 items then only 10 items are visible, when I scroll down and check the 15th item and then press the delete button, it will throw a null-pointer-exception on the check box. The following is my code to delete items from list view using a check box.
deleteButton.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View view) {
System.out.println("Cursor length is " + cursor.getCount());
for (int i = 1; i <= cursor.getCount(); i++) {
listData.recomputeViewAttributes(view);
listData.getResources();
listData.smoothScrollToPosition(i);
view = listData.getChildAt(i-1);
System.out.println("Count is "+i);
CheckBox box = (CheckBox) view.findViewById(R.id.checkBox1);
if (box.isChecked()) {
System.out.println("Box Checked");
/*cursor.moveToPosition(i);
int id = cursor.getInt(0);
System.out.println("Id is " + id);
controller.deleteBookmarkOnId(id);*/
}
}
dialog.dismiss();
}
});