Skip to content Skip to sidebar Skip to footer

How Do I Refresh A Recyclerview In Android?

I am populating the recycler view with new data on Activity result.The problem is the new data is getting append at the end of the recycler view how do I clear the previous da

Solution 1:

Notify your adapter to reflect the changes

mAdapter.notifyDataSetChanged();

Solution 2:

clear your array list before adding object into:

private ArrayList prepareData() {
                books_list.clear();
                for (int i = 0; i < book_id.length; i++) {
                    BooksInfo booksInfo = new BooksInfo();
                    booksInfo.setTitle(title[i]);
                    booksInfo.setPrice(price[i]);
                    booksInfo.setVol_no(vol_no[i]);
                    booksInfo.setStatus(status[i]);
                    booksInfo.setISBN(ISBN[i]);
                    booksInfo.setBook_id(book_id[i]);
                    booksInfo.setBrand(brand[i]);
                    booksInfo.setBook_code(book_code[i]);
                    booksInfo.setSku(sku[i]);
                    booksInfo.setLang(lang[i]);
                    books_list.add(booksInfo);            
                }                      
                return books_list;
            }

Solution 3:

Solution 4:

Just clean your adapter's data, add new data to it and then call notifyDataSetChanged() on your adapter:

yourDataList.clear();
yourDataList.addNewObjects();
adapter.notifyDataSetChanged();

Post a Comment for "How Do I Refresh A Recyclerview In Android?"