Advertisement
Guest User

Untitled

a guest
Jul 3rd, 2015
182
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.40 KB | None | 0 0
  1. public class CommentCursorAdapter extends CursorAdapter{
  2. (...)
  3. @Override
  4. public void bindView(View view, Context arg1, Cursor cursor) {
  5. (...)
  6. holder.list_item_comment_discard_btn.setOnClickListener(new OnClickListener() {
  7. @Override
  8. public void onClick(View v) {
  9. final String _id = v.getTag().toString();
  10. AlertDialog.Builder builder = new AlertDialog.Builder(mActivity);
  11. builder.setTitle("Delete");
  12. builder.setMessage("Do you want to delete "+_id);
  13. builder.setPositiveButton(android.R.string.ok, new DialogInterface.OnClickListener() {
  14. public void onClick(DialogInterface dialog, int id) {
  15. // User clicked OK button
  16. DBAdapter dba = new DBAdapter(mActivity);
  17. dba.open();
  18. dba.remove(_id);
  19. Log.i("TAAG", "removed: "+_id);
  20. dba.close();
  21.  
  22. // How to update the listview ??
  23. }
  24. });
  25. builder.setNegativeButton(android.R.string.cancel, new DialogInterface.OnClickListener() {
  26. public void onClick(DialogInterface dialog, int id) {
  27. // User cancelled the dialog
  28. }
  29. });
  30.  
  31. AlertDialog d = builder.create();
  32. d.show();
  33. }
  34. });
  35. holder.list_item_comment_discard_btn.setTag(_id);
  36. (...)
  37. }
  38. (...)
  39. }
  40.  
  41. public void onCreate(Bundle savedInstanceState) { // or onStart
  42. // ...
  43. this.getLoaderManager().initLoader(MY_CURSOR_ID, null, this);
  44. // ...
  45. }
  46.  
  47. public Loader<Cursor> onCreateLoader(int id, Bundle args) {
  48. // TODO: create a cursor loader that will load your cursor here
  49. }
  50.  
  51. public void onLoadFinished(Loader<Cursor> arg0, final Cursor arg1) {
  52. // TODO: set your cursor as the cursor of your adapter here;
  53. }
  54.  
  55. public void onLoaderReset(Loader<Cursor> arg0) {
  56. // TODO: set null as the cursor of your adapter and 'free' all cursor
  57. // references;
  58. }
  59.  
  60. this.getLoaderManager().restartLoader(MY_CURSOR_ID, null, this);
  61.  
  62. public void onClick(DialogInterface dialog, int id) {
  63. // User clicked OK button
  64. DBAdapter dba = new DBAdapter(mActivity);
  65. dba.open();
  66. dba.remove(_id);
  67. Log.i("TAAG", "removed: "+_id);
  68. dba.close();
  69. cursor.requery();
  70. notifyDataSetChanged();
  71. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement