0

I would like to implement the delete functionality in listview. I want it to act it like most common android apps (like the email client..etc). What I mean, is that when you click on delete button then the list will have check boxes in which you can check and then proceed with the delete.

I have my list view, but I am not sure about how the check box will appear (and will respond to clicks as opposed to the whole item responding to click), Any pointers on that? I thoght I would ask you first before I go on reinventing the wheel or bang my head against the wall.

Thank you so much

Snake
  • 14,228
  • 27
  • 117
  • 250
  • which layout your are using for your item? I mean you are using android layout which was predefined or your custom layout. – Pratik Sep 28 '12 at 05:15

3 Answers3

1

You can include checkbox in the listview row.xml and make its Visibility as GONE, then when you click on a Button that enables all the CheckBoxes just set a boolean true and referesh the ListView. On the basis of the boolean write the logic in getView() as

if(deleted_button_clicked){
  checkboxes.setVisibility(View.VISIBLE);
}
else{
  checkboxes.setVisibility(View.GONE);
}

And further for deleting you having to get the checked items and perform deletion of Data from the ListView and refresh the ListView again.

Update

Further you can have a look at my blog about the ListView with CheckBox.

Lalit Poptani
  • 67,150
  • 23
  • 161
  • 242
  • Thanks for the answer. I I looked at the codes on please correct me if I am wrong. I the item in the list will respond to clicks and check the check box. I however I am looking to check the box checkbox only when the checkbox is clicked not the list item – Snake Sep 28 '12 at 18:15
  • @Snake I had provided my blog address refer that also it includes the demo in github – Lalit Poptani Sep 29 '12 at 04:55
0

Putting a checkbox in a listview is a tedious job. I faced some of those probs and when I found a working solution, I posted it here. It has everything except the delete part. Hope it helps u.

Community
  • 1
  • 1
Akhil
  • 13,888
  • 7
  • 35
  • 39
-1

With you listView you can set following...

listView.setChoiceMode(CHOICE_MODE_MULTIPLE);
listView.setAdapter(new ArrayAdapter<String>(this,
                android.R.layout.simple_list_item_multiple_choice, fields));

See the working example at Here

Jigar Pandya
  • 6,004
  • 2
  • 27
  • 45