Removing item in RecyclerView cause view overlap like this video Link
fragment_feed.xml
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:orientation="vertical" android:layout_width="match_parent"
android:layout_height="match_parent">
<android.support.v7.widget.RecyclerView
android:id="@+id/recyclerView"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:scrollbars="none" />
In Adapter
holder.setIsRecyclable(false);
((PostViewHolder) holder).mUsername.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
deleteItem(holder.getAdapterPosition());
}
});
void deleteItem(int index) {
postList.remove(index);
notifyItemRemoved(index);
}
When i change notifyItemRemoved(index); to notifyDataSetChanged(); seem to solved my problem but it's cause remove animation destroyed.
I try to find solution to solve this but It's seem like no one have the same problem with me. Thanks for answer
EDIT
@Override
public void onBindViewHolder(final RecyclerView.ViewHolder holder, final int position) {
holder.setIsRecyclable(false);
if (holder instanceof PostViewHolder) {
Post post = (Post) postList.get(position);
String type = post.getTypePost();
// Inflate Layout //
LayoutInflater inflater = LayoutInflater.from(mContext);
((PostViewHolder) holder).mUsername.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
deleteItem(holder.getAdapterPosition());
}
});
((PostViewHolder) holder).mUsername.setText(post.getOwnerPost());
} else if (holder instanceof HeaderViewHolder) {
} else{
((ProgressViewHolder) holder).progressBar.setIndeterminate(true);
}
}