I am currently facing a stupid problem. I have a list with a custom adapter (extension CursorAdapter).
Displays a custom view with different buttons (sharing, such as deleting). For the delete button, it has an alertdialog to confirm the removal of the item. When the user confirms, the item is removed from db. Everything is working fine while here.
My question is, how can I effectively update my list with my new dataset?
Many thanks for your help.
The code:
public class CommentCursorAdapter extends CursorAdapter{
(...)
@Override
public void bindView(View view, Context arg1, Cursor cursor) {
(...)
holder.list_item_comment_discard_btn.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
final String _id = v.getTag().toString();
AlertDialog.Builder builder = new AlertDialog.Builder(mActivity);
builder.setTitle("Delete");
builder.setMessage("Do you want to delete "+_id);
builder.setPositiveButton(android.R.string.ok, new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int id) {
DBAdapter dba = new DBAdapter(mActivity);
dba.open();
dba.remove(_id);
Log.i("TAAG", "removed: "+_id);
dba.close();
}
});
builder.setNegativeButton(android.R.string.cancel, new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int id) {
}
});
AlertDialog d = builder.create();
d.show();
}
});
holder.list_item_comment_discard_btn.setTag(_id);
(...)
}
(...)
}
source
share