machinezhou
machinezhou

Reputation: 689

recyclerview change item decoration when size changed

as it said, how can I change item decoration in recyclerview when size changed? I've already tried invalidate(), but nothing changed.So is there some sort of methods like "notifydataset"?

Upvotes: 0

Views: 2285

Answers (1)

kuljeet singh
kuljeet singh

Reputation: 2852

the adapter will be a good candidate to handle the events.

If you want to add or remove items from the adapter, you will need to explicitly inform to the adapter. That’s a bit different from the former notifyDataSetChanged():

  public void add(ViewModel item, int position) {
        items.add(position, item);
        notifyItemInserted(position);
    }

    public void remove(ViewModel item) {
        int position = items.indexOf(item);
        items.remove(position);
        notifyItemRemoved(position);
    }

Upvotes: 4

Related Questions