A
A
Alexander Sinitsyn2018-03-30 12:39:35
Android
Alexander Sinitsyn, 2018-03-30 12:39:35

How to access RecyclerView's ViewHolder to call its draw method?

There is an adapter private class MyAdapter extends RecyclerView.Adapter
and private class ItemHolder extends RecyclerView.ViewHolder
Rendering is done in updateHolder when called in ItemHolder bindItem

public void bindItem(ItemClass item) {

  mItem = item;
  updateHolder();
}

from
@Override
        public void onBindViewHolder(ItemHolder holder, int position) {

            holder.bindItem(mItems.get(position));
        }

UpdateHolder() uses some external value, depending on which mItem.field1 or mItem.field2 is displayed.
How, when changing the value of an external value, to redraw all the elements of the list only by calling updateHolder()?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
D
Denis Zagaevsky, 2018-03-30
@a_u_sinitsin

UpdateHolder() uses some external value, depending on which mItem.field1 or mItem.field2 is displayed.

This is not very good practice. It is better that all the data lies in the data element. When the data changes, the list with the data must change, DiffUtil should be called, and the data change should be transferred to the adapter.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question