Removing Recyclerview Items
I have a RecyclerView which is adding items each certain period. When adding objects, if list items are more than (lets say) 500, then the first items will be removed and the new i
Solution 1:
You're telling your view that you changed your whole adapter. For additions, deletions and reorders consider using the following methods:
notifyItemRangeChanged
notifyItemRangeInserted
notifyItemRangeRemoved
notifyItemMoved
notifyItemInserted
notifyItemChanged
notifyItemRemoved
So in your case you're removing the top count items so:
notifyItemRangeRemoved(0,count)
should do the work.
Solution 2:
publicclassviewHolderFavextendsRecyclerView.ViewHolder {
privateImageView image;
privateTextView name;
publicviewHolderFav( View itemView ) {
super( itemView );
image = ( ImageView ) itemView.findViewById( R.id.txt_image_fav );
name = ( TextView ) itemView.findViewById( R.id.txt_name_fav );
edite.setOnClickListener( newView.OnClickListener( ) {
@OverridepublicvoidonClick( View v ) {
remove( posts.get( getLayoutPosition() ) );
}
} );
}
publicvoidremove(DataBoj item) {
int position = posts.indexOf(item);
posts.remove(position);
notifyItemRemoved(position);
}
Post a Comment for "Removing Recyclerview Items"