well you have a list, and adapter, and a recyclerview
ArrayList<String> myQuoteList = new ArrayList<String>();
MyCustomAdapter adapter = new MyCustomAdapter(myQuoteList);
rcvQuotes.setAdapter(adapter);
Then in your delete you can just do
private void deleteAtIndex(int index){
myQuoteList.remove(index);
adapter.notifyDataSetChanged();
}
//make a interface.
public interface fragmentCallback{
boolean onQuoteDeleted(Quote deleteQuote);
}
have your activity implement the interface:
myActivity implements fragmentCallback{
public boolean onQuoteDeleted(Quote deletedQuote){
if(myQuotelist.contains(deleteQuote){
myQuoteList.remove(deleteQuote);
adapter.notifyDataSetChanged();
}
}
}
then in fragment simpley
myFragment.setQuote(selectedQuote);
inside of fragment just do:
@Override
public void onAttach(Context context) {
super.onAttach(context);
try{
mFragmentCallback = (IFragmentCallback) context;
}catch (Exception ex){
A35Log.e(TAG, "Parent Context does not implement fragmentCallback");
}
}
public void setQuote(Quote showQuote){
mSelectedQuote = showQuote;
}
btnDelete_onClick(){
if(mFragmentCallback != null){
mFragmentCallback.onDeleteQuote(mSelectedQuote);
}
}
you can handle it by selected index of the row, or by last index, or first index, or you can add a long touch listener or trash can to the row item. how you get the index is up to you.
That's it, that is all there is to it.