Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- 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) {
- // User clicked OK button
- DBAdapter dba = new DBAdapter(mActivity);
- dba.open();
- dba.remove(_id);
- Log.i("TAAG", "removed: "+_id);
- dba.close();
- // How to update the listview ??
- }
- });
- builder.setNegativeButton(android.R.string.cancel, new DialogInterface.OnClickListener() {
- public void onClick(DialogInterface dialog, int id) {
- // User cancelled the dialog
- }
- });
- AlertDialog d = builder.create();
- d.show();
- }
- });
- holder.list_item_comment_discard_btn.setTag(_id);
- (...)
- }
- (...)
- }
- public void onCreate(Bundle savedInstanceState) { // or onStart
- // ...
- this.getLoaderManager().initLoader(MY_CURSOR_ID, null, this);
- // ...
- }
- public Loader<Cursor> onCreateLoader(int id, Bundle args) {
- // TODO: create a cursor loader that will load your cursor here
- }
- public void onLoadFinished(Loader<Cursor> arg0, final Cursor arg1) {
- // TODO: set your cursor as the cursor of your adapter here;
- }
- public void onLoaderReset(Loader<Cursor> arg0) {
- // TODO: set null as the cursor of your adapter and 'free' all cursor
- // references;
- }
- this.getLoaderManager().restartLoader(MY_CURSOR_ID, null, this);
- public void onClick(DialogInterface dialog, int id) {
- // User clicked OK button
- DBAdapter dba = new DBAdapter(mActivity);
- dba.open();
- dba.remove(_id);
- Log.i("TAAG", "removed: "+_id);
- dba.close();
- cursor.requery();
- notifyDataSetChanged();
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement