如何在使用ItemTouchHelper滑动后重置recyclerview项目

时间:2016-02-16 14:18:40

标签: android android-recyclerview

我有recyclerviewitem,在左侧滑动时,我使用以下代码在recyclerview项目的顶部创建一个图像,我能够在项目顶部获取图像,但我无法重置recyclelerviewitem之后滑动,而不是清除整个项目

代码:

 ItemTouchHelper.SimpleCallback simpleItemTouchCallback = new ItemTouchHelper.SimpleCallback(0, ItemTouchHelper.LEFT | ItemTouchHelper.RIGHT){

            @Override
            public boolean onMove(RecyclerView arg0,
                    RecyclerView.ViewHolder arg1,
                    RecyclerView.ViewHolder arg2) {
                // TODO Auto-generated method stub
                return false;
            }


            public void onChildDraw(android.graphics.Canvas c, RecyclerView recyclerView, RecyclerView.ViewHolder viewHolder, float dX, float dY, int actionState, boolean isCurrentlyActive) {

                if (actionState == ItemTouchHelper.ACTION_STATE_SWIPE && isCurrentlyActive) {
                    // Get RecyclerView item from the ViewHolder
                    View itemView = viewHolder.itemView;





                    Drawable d = ContextCompat.getDrawable(getContext(), R.drawable.swipeleft);
                    d.setBounds(itemView.getLeft(), itemView.getTop(), (int) dX, itemView.getBottom());
                    d.draw(c);


                }
                super.onChildDraw(c, recyclerView, viewHolder, dX, dY, actionState, isCurrentlyActive);

            };

            @Override
            public void onSwiped(
                    RecyclerView.ViewHolder viewHolder,
                    int Swipedir) {




            }

        };

0 个答案:

没有答案