我在我的应用程序中使用 Roman Nurik 的 SwipeListViewTouchListener
来关闭列表项。
这就是我正在做的:
SwipeListViewTouchListener touchListener2 =
new SwipeListViewTouchListener(
lv,
new SwipeListViewTouchListener.OnSwipeCallback() {
@Override
public void onSwipeLeft(ListView listView, int [] reverseSortedPositions) {
Toast.makeText(MainActivity.this, "LEFT", Toast.LENGTH_SHORT).show();
}
@Override
public void onSwipeRight(ListView listView, int [] reverseSortedPositions) {
}
},
true, // example : left action = dismiss
true); // example : right action without dismiss animation
lv.setOnTouchListener(touchListener2);
lv.setOnScrollListener(touchListener2.makeScrollListener());
现在我的问题是如何从列表中删除被忽略的项目(比如
customAdapter.remove(position);
并通知适配器
customAdapter.notifyDataSetChanged();
最佳答案
试试这个...
public void onSwipeLeft(ListView listView, int[] reverseSortedPositions) {
Toast.makeText(MainActivity.this, "LEFT", Toast.LENGTH_SHORT).show();
if (reverseSortedPositions != null && reverseSortedPositions.length>0) {
for (int i : reverseSortedPositions) {
customAdapter.remove(i);
}
customAdapter.notifyDataSetChanged();
}
}
关于android - 无法获得项目位置以关闭列表项目,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20327970/