Hi, I have a RecyclerView with its corresponding adapter class that extends the following: extends RecyclerView.Adapter<UsuariosAdaptador.MyViewHolder>
That adapter I pass a Cursor and I find the following problem:
When I populated a RecyclerView with an ArrayList for example, if I wanted to delete an element and give it an effect through the method rv.setItemAnimator(new DefaultItemAnimator());
I used the following code in my adapter:
@Override
public void onBindViewHolder(MyViewHolder holder, final int position) {
//delete es una ImageView
holder.delete.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
lista.remove(position); //Lista es un ArrayList
notifyItemRemoved(position);
notifyItemRangeChanged(position,getItemCount());
}
});
}
Well, that works perfectly for me, but the problem comes when I want to do that with a Cursor, of course, you can not erase a Cursor tuples (as far as I know).
How should I do it? Returning to make a query to the BD, doing it next a swapcursor()
and indicating the position where was the field that I deleted?