Friday, 13 September 2013

delete items from listview in android

delete items from listview in android

I have listview which contains itemname and checkbox in front of item
name, and one delete button below layout, if my list contain 15 items then
only 10 items are visible, when i scoll down and check 15 item and then
press delete button, it will give the null pointer exception on check box,
following is my code to delete items from list view using 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);
box = (CheckBox) view.findViewById(i-1);
System.out.println("Count is "+i);
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();
}
});

No comments:

Post a Comment