android滑动以消除listview不会删除项目
作者:互联网
I’m using this library使用滑动以关闭功能来创建列表视图.
我正在使用ArrayAdapter并使用此代码创建滑动以关闭侦听器
SwipeDismissListViewTouchListener touchListener =
new SwipeDismissListViewTouchListener(
listView,
new SwipeDismissListViewTouchListener.DismissCallbacks() {
@Override
public boolean canDismiss(int position) {
return true;
}
@Override
public void onDismiss(ListView listView, int[] reverseSortedPositions) {
for (int position : reverseSortedPositions) {
mAdapter.remove(mAdapter.getItem(position));
}
mAdapter.notifyDataSetChanged();
}
});
listView.setOnTouchListener(touchListener);
// Setting this scroll listener is required to ensure that during ListView scrolling,
// we don't look for swipes.
listView.setOnScrollListener(touchListener.makeScrollListener());
但是每次尝试滑动时,似乎都可以,但随后该项目又回来了.
日志猫不会抛出任何异常.
有人以前有这个错误吗?请帮忙.
解决方法:
当我使用Roman Nurik的滑动擦除时,遇到了相同的问题.在适配器中创建自己的删除方法:
public void remove(int position) {
yourList.remove(position);
}
您应该这样称呼它:
@Override
public void onDismiss(ListView listView, int[] reverseSortedPositions) {
for (int position : reverseSortedPositions) {
mAdapter.remove(position);
}
mAdapter.notifyDataSetChanged();
}
标签:listview,android-arrayadapter,android,android-adapter 来源: https://codeday.me/bug/20191029/1959029.html