Android 无法获取项目位置以取消listitem
我正在我的应用程序中使用Roman Nurik的Android 无法获取项目位置以取消listitem,android,android-listview,swipe,Android,Android Listview,Swipe,我正在我的应用程序中使用Roman Nurik的SwipeListViewTouchListener关闭列表项。 这就是我正在做的: SwipeListViewTouchListener touchListener2 = new SwipeListViewTouchListener( lv, new SwipeListViewTouchListener.OnSwipeCallback(
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();
}
}
试试这个
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();
}
}
您回答了您的问题。请从适配器中删除该项,然后调用notifyDataSetChangedwhat's problem if you have adapter just do you want.@keshav但我无法获取toouchlistiner2中位置的值。是否从中获取数据db@Sparkplug您的customAdapter是什么?是扩展BaseApter还是ArrayAdapter?您回答yo您的问题。从适配器中删除该项并调用notifyDataSetChangedwhat's problem if you have adapter just do you want.@keshav但我无法获取toouchlistiner2中位置的值。您从中获取数据吗db@Sparkplug什么是您的customAdapter?是扩展BaseApter还是ArrayAdapter?谢谢,伙计。现在它可以工作了正如计划的那样。谢谢你,伙计。现在它正在按计划工作。