TableView: The problem with addRowRange
public void addItemRange(int positionStart, int itemCount, List<T> items) {
if (m_jItemList.size() > positionStart + itemCount && items != null) {
for (int i = positionStart; i < positionStart + itemCount + 1; i++) {
if (i != RecyclerView.NO_POSITION) {
m_jItemList.add(i, items.get(i));
}
}
notifyItemRangeInserted(positionStart, itemCount);
}
}
- The source code to add item range.
- The list size is never gonna greater than position start + item count +1.
- Do u mean m_jItemList.size() >= positionStart?
- for (int i = positionStart; i < positionStart + itemCount + 1; i++) { and dont add 1 its gonna get null in items if you adding it at the ends of Cells
What i am change is positionStart is the where to adding the item itemCount is the total of the New item you want to add, items is the new list of the item.
public void addItemRange(int positionStart, int itemCount, List<T> items) {
if (m_jItemList.size() >= positionStart && items != null) {
for (int i = positionStart; i < positionStart + itemCount; i++) {
if (i != RecyclerView.NO_POSITION) {
m_jItemList.add(i, items.get(i - positionStart));
}
}
notifyItemRangeInserted(positionStart, itemCount);
}
}
Also there is issue with removeRowRange.
public void deleteItemRange(int positionStart, int itemCount) {
if (m_jItemList.size() >= positionStart + itemCount) {
for (int i = positionStart; i < positionStart + itemCount; i++) {
if (i != RecyclerView.NO_POSITION) {
m_jItemList.remove(positionStart);
}
}
notifyItemRangeRemoved(positionStart, itemCount);
}
}
Do u think it should be remove the Same position not the i because the List getting smaller. otherwise it gonna out of position
About this issue
- Original URL
- State: closed
- Created 6 years ago
- Reactions: 2
- Comments: 17 (8 by maintainers)
Commits related to this issue
- Dynamically adding row used to get problem. This problem has been resolved. #19 issue has been fixed. — committed to evrencoskun/TableView by evrencoskun 6 years ago
- Unnecessary controls & parameters have been removed for #19 issue has been fixed. — committed to evrencoskun/TableView by evrencoskun 6 years ago
Yes, Looks good now, Thank you for the great work!