Skip to content

Commit

Permalink
Merge pull request #341 from Ludejin/master
Browse files Browse the repository at this point in the history
overload addData function to add data to certain location
  • Loading branch information
CymChad authored Sep 20, 2016
2 parents 61a4235 + 71cdc1d commit 96f8a24
Showing 1 changed file with 28 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -221,6 +221,34 @@ public void setNewData(List<T> data) {
notifyDataSetChanged();
}

/**
* add one new data in to certain location
* @param position
*/
public void addData(int position, T data) {
if (0 <= position && position < mData.size()) {
mData.add(position, data);
notifyItemInserted(position);
notifyItemRangeChanged(position, mData.size() - position);
} else {
throw new ArrayIndexOutOfBoundsException("inserted position most greater than 0 and less than data size");
}
}

/**
* add new data in to certain location
* @param position
*/
public void addData(int position, List<T> data) {
if (0 <= position && position < mData.size()) {
mData.addAll(position, data);
notifyItemInserted(position);
notifyItemRangeChanged(position, mData.size() - position - data.size());
} else {
throw new ArrayIndexOutOfBoundsException("inserted position most greater than 0 and less than data size");
}
}

/**
* additional data;
*
Expand Down

0 comments on commit 96f8a24

Please sign in to comment.