I'm trying to change the field with time in my RecyclerView
. Each individual ViewHolder
contains a CardView
and a few more views inside. The only view I want to animate is the one with time. As you can see, there is no animation:
adapter.notifyDataSetChanged();
Updating items one by one doesn't help because then the whole CardView
flashes:
int len = adapter.getItemCount();
for(int i=0;i<len;i++) {
adapter.notifyItemChanged(i);
}
Is there a way to get a list of all ViewHolders
to then update (animate) just that one TextView
inside each one?
You can notify your
RecyclerView.Adapter
's observers to issue a partial update of yourRecyclerView.ViewHolders
by passing a payloadObject
.Where
payload
could be or contain a flag that represents relative or absolute time. To bind thepayload
to your view holders, override the followingonBindViewHolder(viewHolder, position, payloads)
method in your adapter, and check thepayloads
parameter for data.Within your
MyViewHolder.bindTimePayload(payload)
method, update your timeTextViews
to the time format specified in thepayload
.