1
1
package com .github .meafs .recover .adapters ;
2
2
3
+ import android .annotation .SuppressLint ;
3
4
import android .content .Context ;
4
5
import android .content .DialogInterface ;
5
6
import android .view .LayoutInflater ;
20
21
import java .util .ArrayList ;
21
22
22
23
public class ReminderAdapter extends RecyclerView .Adapter <ReminderAdapter .myviewholder > {
23
- ArrayList <ReminderModel > dataholder = new ArrayList <ReminderModel >(); //array list to hold the reminders
24
+ ArrayList <ReminderModel > dataholder = new ArrayList <>(); //array list to hold the reminders
24
25
private Context context ;
26
+
25
27
public ReminderAdapter (ArrayList <ReminderModel > dataholder ) {
26
28
27
29
this .dataholder = dataholder ;
@@ -36,34 +38,40 @@ public myviewholder onCreateViewHolder(@NonNull ViewGroup parent, int viewType)
36
38
}
37
39
38
40
@ Override
39
- public void onBindViewHolder (@ NonNull myviewholder holder , int position ) {
41
+ public void onBindViewHolder (@ NonNull myviewholder holder , @ SuppressLint ( "RecyclerView" ) int position ) {
40
42
holder .mTitle .setText (dataholder .get (position ).getTitle ()); //Binds the single reminder objects to recycler view
41
43
holder .mDate .setText (dataholder .get (position ).getDate ());
42
44
holder .mTime .setText (dataholder .get (position ).getTime ());
43
45
holder .mPatient .setText (dataholder .get (position ).getPname ());
44
46
holder .reminder_rv_layout .setOnClickListener (new View .OnClickListener () {
45
47
@ Override
46
48
public void onClick (View view ) {
47
- AlertDialog .Builder adb = new AlertDialog .Builder (context );
49
+ AlertDialog .Builder adb = new AlertDialog .Builder (context );
48
50
adb .setTitle ("Delete?" );
49
51
adb .setMessage ("Are you sure you want to delete " + position );
50
52
final int positionToRemove = position ;
51
53
adb .setNegativeButton ("Cancel" , null );
52
54
adb .setPositiveButton ("Ok" , new AlertDialog .OnClickListener () {
53
55
public void onClick (DialogInterface dialog , int which ) {
54
- String title =(String ) ((TextView ) view .findViewById (R .id .txtTitle )).getText ();
55
- String date =(String ) ((TextView ) view .findViewById (R .id .txtDate )).getText ();
56
- String time =(String ) ((TextView ) view .findViewById (R .id .txtTime )).getText ();
57
- String pname =(String ) ((TextView ) view .findViewById (R .id .txtPname )).getText ();
56
+ String title = (String ) ((TextView ) view .findViewById (R .id .txtTitle )).getText ();
57
+ String date = (String ) ((TextView ) view .findViewById (R .id .txtDate )).getText ();
58
+ String time = (String ) ((TextView ) view .findViewById (R .id .txtTime )).getText ();
59
+ String pname = (String ) ((TextView ) view .findViewById (R .id .txtPname )).getText ();
60
+
58
61
String result = new dbManager (context ).deleteReminder (title , date , time , pname );
59
62
Toast .makeText (context , result , Toast .LENGTH_SHORT ).show ();
60
- notifyDataSetChanged ();
61
- }});
63
+
64
+ dataholder .remove (position );
65
+ notifyItemRemoved (position );
66
+ notifyItemRangeChanged (position , getItemCount ());
67
+ }
68
+ });
62
69
adb .show ();
63
70
}
64
71
});
65
72
}
66
73
74
+
67
75
@ Override
68
76
public int getItemCount () {
69
77
return dataholder .size ();
@@ -77,11 +85,11 @@ class myviewholder extends RecyclerView.ViewHolder {
77
85
public myviewholder (@ NonNull View itemView ) {
78
86
super (itemView );
79
87
80
- mTitle = ( TextView ) itemView .findViewById (R .id .txtTitle ); //holds the reference of the materials to show data in recyclerview
81
- mDate = ( TextView ) itemView .findViewById (R .id .txtDate );
82
- mTime = ( TextView ) itemView .findViewById (R .id .txtTime );
83
- mPatient = ( TextView ) itemView .findViewById (R .id .txtPname );
84
- reminder_rv_layout = ( CardView ) itemView .findViewById (R .id .reminder_item_layout );
88
+ mTitle = itemView .findViewById (R .id .txtTitle ); //holds the reference of the materials to show data in recyclerview
89
+ mDate = itemView .findViewById (R .id .txtDate );
90
+ mTime = itemView .findViewById (R .id .txtTime );
91
+ mPatient = itemView .findViewById (R .id .txtPname );
92
+ reminder_rv_layout = itemView .findViewById (R .id .reminder_item_layout );
85
93
}
86
94
}
87
95
}
0 commit comments