Add a new item to recyclerview programmatically?
if you are adding multiple items to the list use this:
mAdapter.notifyItemRangeInserted(startPosition, itemcount);
This notify any registered observers that the currently reflected itemCount items starting at positionStart have been newly inserted. The item previously located at positionStart and beyond can now be found starting at position positinStart+itemCount
existing item in the dataset still considered up to date.
simply add to your data structure ( mItems ) , and then notify your adapter about dataset change
private void addItem(String item) {
mItems.add(item);
mAdapter.notifyDataSetChanged();
}
addItem("New Item");
First add your item to mItems
and then use:
mAdapter.notifyItemInserted(mItems.size() - 1);
this method is better than using:
mAdapter.notifyDataSetChanged();
in performance.