I have 10 items in my activity. They are displayed in a RecyclerView. The itms are stored in a list;
List<CustomItem> items = new ArrayList<>();
I pass them to the RecyclerView adapter like so:
recyclerView.setAdapter(new RVAdapter(this, items));
Now, whenever I do filter the items by a string query, so that the recycler view displays a subset of the items by description, for instance, I have to pass a filtered list of items to the recycler view, like so:
List<CustomItem> filteredItems = CustomItem.filterByQuery(items, query);
and then I:
adapter.setItemList(filteredItems);
notifyDataSetChanged();
-> which sets the filtered items in place of the items
I sent to it in the constructor, and effectively overrids the activity items
because they both point to the same objects in memory.
And I realized that by filtering in order to display a subset of results, I am overriding the acitivy's list of items, because it is shared by the activity and the RecyclerView
However, of all the code samples and tutorials I've seen on RecyclerView
, I've never seen anyone do a deep copy of the list of items and pass it to the RV, so what am I missing here?