删除事件
/**
* 删除Item
*/
private void deleteItem() {
int size = mListItems.size();
if (size > 0) {
mListItems.remove(mDelId);
mAdapter.notifyDataSetChanged();
}
}
(1)mDelId是用于记录当前Item位置,以便删除相应的Item,该变量在前面已经定义
private static int mDelId = 0;
(2)remove函数系统已经定义,源码如下
public E remove(int location) {
if (location >= 0 && location < size) {
Linklink = voidLink;
if (location < (size / 2)) {
for (int i = 0; i <= location; i++) {
link = link.next;
}
} else {
for (int i = size; i > location; i--) {
link = link.previous;
}
}
Linkprevious = link.previous;
Linknext = link.next;
previous.next = next;
next.previous = previous;
size--;
modCount++;
return link.data;
}
throw new IndexOutOfBoundsException();
}
(3)注意使用notifyDataSetChanged方法用于Item的动态更新,源码如下。
public void notifyDataSetChanged() {
super.notifyDataSetChanged();
mNotifyOnChange = true;
}