Monday, 19 August 2013

remove item from listview and from diplay

remove item from listview and from diplay

In my code there is a listview in which i am doing an operation to delete
the listview item. it works but remains displayed in the listview. It is
in the second activity.It disappears only after going to the firstactivity
and then returns.Please give me the changes that i have to make.
Getclicker.java
public void onItemClick(AdapterView<?> a, View v, int position, final long
id) {
AlertDialog.Builder adb=new
AlertDialog.Builder(Getclicker.this);
adb.setTitle("Delete?");
adb.setMessage("Are you sure you want to delete the
event" + (position+1));
final int positionToRemove = position;
adb.setNegativeButton("Cancel", null);
adb.setPositiveButton("Ok", new
AlertDialog.OnClickListener() {
@Override
public void onClick(DialogInterface dialog,
int which) {
eventsData1.delete( id);
adapter.notifyDataSetChanged();
}});
adb.show();
}
delete method in database
public void delete(long id) {
SQLiteDatabase db = this.getReadableDatabase();
db.delete(DATABASE_TABLE, KEY_ROWID + " = ?",
new String[] { String.valueOf(id )});
db.close();
}

No comments:

Post a Comment