RecyclerView ItemTouchHelper Buttons on Swipe

后端 未结 11 1270
春和景丽
春和景丽 2020-11-27 11:05

I am trying to port some iOS functionality to Android.

I intent to create a table where on swipe to the left shows 2 button: Edit and Delete.

I have

11条回答
  •  离开以前
    2020-11-27 11:20

    If you use a RecyclerView, try to use OnScrollListener. Do something like this.

     private class YourOnScrollListener extends RecyclerView.OnScrollListener {
    
        private boolean directionLeft;
    
        @Override
        public void onScrollStateChanged(RecyclerView recyclerView, int newState) {
            if (newState == RecyclerView.SCROLL_STATE_IDLE) {
                if (directionLeft) drawButtons();
                //Draw buttons here if you want them to be drawn after scroll is finished
                //here you can play with states, to draw buttons or erase it whenever you want
            }
        }
    
        @Override
        public void onScrolled(RecyclerView recyclerView, int dx, int dy) {
            super.onScrolled(recyclerView, dx, dy);
            if (dx < 0) directionLeft = true;
            else directionLeft = false;
        }
    
    }
    

提交回复
热议问题