如何限制onSwiped()忽略一个方向?

时间:2016-01-11 04:25:38

标签: android

我有一个onSwiped()在向右滑动而不向左滑动时做了必要的事情,问题是它仍然滑动,我希望它能够"冻结"当向左滑动时。

 ItemTouchHelper itemTouchHelper = new ItemTouchHelper(new ItemTouchHelper.SimpleCallback(ItemTouchHelper.START | ItemTouchHelper.END,
                ItemTouchHelper.START | ItemTouchHelper.END) {
                @Override
                 public boolean onMove(RecyclerView recyclerView, RecyclerView.ViewHolder viewHolder, RecyclerView.ViewHolder target) {
                return false;
            }
            @Override
            public void onSwiped(RecyclerView.ViewHolder viewHolder, int direction) {

                Log.d(TAG, "whats swiped " + viewHolder.getAdapterPosition() + "   direction: " + direction + "   arrayListCountyNames.get(viewHolder.getAdapterPosition())" + arrayListCountyNames.get(viewHolder.getAdapterPosition()));
                if (direction==16) {//do something}

1 个答案:

答案 0 :(得分:0)

创建ItemTouchHepler.RIGHT时,您应该将ItemTouchHelper.SimpleCallback作为第二个参数传递:

ItemTouchHelper itemTouchHelper = new ItemTouchHelper(new ItemTouchHelper.SimpleCallback(ItemTouchHelper.START | ItemTouchHelper.END,
            ItemTouchHelper.RIGHT));