Skip to content

Commit

Permalink
fix insert/delete item crash issue
Browse files Browse the repository at this point in the history
  • Loading branch information
Jamling committed May 17, 2017
1 parent 2f9f3d4 commit 30b4fe2
Showing 1 changed file with 9 additions and 3 deletions.
12 changes: 9 additions & 3 deletions library/src/cn/ieclipse/af/adapter/AfRecyclerAdapter.java
Original file line number Diff line number Diff line change
Expand Up @@ -113,12 +113,16 @@ public List<T> getDataList() {

public void add(T data) {
mDataHolder.add(data);
notifyItemInserted(getHeaderCount() + mDataHolder.getCount());
int pos = getHeaderCount() + mDataHolder.getCount();
notifyItemInserted(pos);
notifyItemChanged(pos);
}

public void add2Top(T data) {
mDataHolder.add2Top(data);
notifyItemInserted(getHeaderCount());
int pos = getHeaderCount();
notifyItemInserted(pos);
notifyDataSetChanged();
}

public void add2Top(List<T> list) {
Expand Down Expand Up @@ -161,7 +165,9 @@ public void deleteItem(int position, boolean isLayoutPosition) {
// 删除后不为空,更新item
if (mDataHolder.getCount() > 0) {
if (obj != null) {
notifyItemRemoved(isLayoutPosition ? position : position + getHeaderCount());
int pos = isLayoutPosition ? position : position + getHeaderCount();
notifyItemRemoved(pos);
notifyItemRangeChanged(pos, getItemCount());
}
}
else {
Expand Down

0 comments on commit 30b4fe2

Please sign in to comment.