【问题标题】:android swipe to dismiss listview won't remove itemandroid滑动以关闭listview不会删除项目
【发布时间】:2014-07-25 00:44:48
【问题描述】:

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());

但每次尝试滑动似乎都有效,但随后项目又回来了。

日志猫不会给我任何异常。

以前有人遇到过这个错误吗?请帮忙。

【问题讨论】:

    标签: android listview android-arrayadapter android-adapter


    【解决方案1】:

    当我使用 Roman Nurik 的 swipe-to-dismiss 时,我遇到了同样的问题。在适配器中创建自己的删除方法:

    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();
    }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2020-09-25
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2012-06-22
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多