Reputation: 3137
So, i'm storing my datas in an IO-file! My datas are displayed and i want to delete an item from the listview, i maked this code, and i'm stucking!
L.setOnItemLongClickListener(new OnItemLongClickListener() {
@Override
public boolean onItemLongClick(AdapterView<?> arg0, View arg1,
final int arg2, long arg3) {
AlertDialog alert_reset;
AlertDialog.Builder builder = new AlertDialog.Builder(activity);
builder.setMessage("Supprimer cette donnée ?")
.setCancelable(false)
.setPositiveButton("Oui",
new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog,
int id) {
.............
updatelv(activity);
}
})
.setNegativeButton("Non",
new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog,
int id) {
dialog.cancel();
}
});
alert_reset = builder.create();
alert_reset.show();
return true;
}
Have i to use List.remove(arg2)
?
And for deleting the data from a file, how can i do this ?
Thank you.
Upvotes: 0
Views: 1619
Reputation: 13045
IMHO the easiest way is to start by deleting the entry in the file, and then restart the "buildList" process. As the old entry is no more in the file, the new list won't show it any more.
About deleting in the file, it's more a java based question than Android, and it depends also on the store format you use (xml, json, custom ?). You should consider using a database, which is more flexible and easy to update.
Upvotes: 0
Reputation: 73494
To remove an item from a ListView (which is just a display of some data) you need to remove the item from the data that backs the ListAdapter.
A common example is an Adapter that contains a list. To remove an item from the list and update the ListView you would do something like this.
myList.remove(arg2); // remove the item
myAdapter.notifyDataSetChanged(); // let the adapter know to update
Upvotes: 3