无法获得项目位置以解除列表项目

时间:2013-12-02 12:08:57

标签: android android-listview swipe

我在我的应用中使用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();

1 个答案:

答案 0 :(得分:1)

试试这个......

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();
    }
}
相关问题