I have an xml file for a cardview to be used in a recyclerview in my main android class. This cardview contains a button that will be used to delete the cardview from the list. The problem I have encountered is that all of the buttons in the recyclerview have identical onClick values and I do not know how to differentiate between them.
Here is my button in the cardview xml:
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Delete"
android:id="@+id/btnDelete"
android:onClick="DeleteCard"
android:layout_alignParentTop="true"
android:layout_alignParentRight="true"
android:layout_alignParentEnd="true" />
In my main class, I have a function DeleteCard which runs whenever I press any of the delete buttons. I have a TextView in my cardview as well, and I was wondering if it was possible to somehow retrieve the text that is in the TextView when I press the delete button so I know which one to delete.
This is my onBindViewHolder:
public void onBindViewHolder(TimeViewHolder personViewHolder, int i) {
int min = (int)(times.get(i).time / (60 * 1000));
int remaining = (int)(times.get(i).time % (60 * 1000));
int sec = remaining / 1000;
remaining = remaining % (1000);
int mill = (remaining%1000)/10;
DecimalFormat df = new DecimalFormat("00");
personViewHolder.time.setText(min + ":" + df.format(sec) + "." + mill);
personViewHolder.date.setText(times.get(i).date);
}
I want to get the text from date and use that as a parameter to remove that key in the SharedPreferences. Here is the method that runs when a delete button is pressed:
public void DeleteCard(View view){
SharedPreferences.Editor editor = history.edit();
editor.remove("Date Here");
editor.commit();
}