title: How can I do swipe twice in Recyclerview Android studio
body: <p>I want swipe twice in recyclerview like IoS.
  First swipe, showing button which is delete button or edit,
  And then one more swipe, that item dismiss.</p>
  
  <p>I have done swipe and showing button But I don't know how second swipe.</p>
  
  <p>If you using mail in IoS, more easy understand of second swipe</p>
  
  <p>Here is my Recyclerview swipe helper code</p>
  
  <pre><code>private SwipeActionInterface buttonsActions = null;
  private boolean swipeBack = false;
  private ButtonsState buttonShowedState = ButtonsState.GONE;
  private static final float buttonWidth = 200;
  private RectF buttonInstance = null;
  private RecyclerView.ViewHolder currentItemViewHolder = null;
  
  @Override
  public int getMovementFlags(@NonNull RecyclerView recyclerView, @NonNull RecyclerView.ViewHolder viewHolder) {
      int drag_flags = ItemTouchHelper.UP | ItemTouchHelper.DOWN;
      int swipe_flags = ItemTouchHelper.START | ItemTouchHelper.END;
      return makeMovementFlags(drag_flags, swipe_flags);
  }
  public void getButtonGone(boolean flag){
      if(flag){
          buttonShowedState = ButtonsState.GONE;
      }
  }
  
  @Override
  public boolean onMove(@NonNull RecyclerView recyclerView, @NonNull RecyclerView.ViewHolder viewHolder, @NonNull RecyclerView.ViewHolder target) {
  
      return false;
  }
  
  
  @Override
  public void onSwiped(@NonNull RecyclerView.ViewHolder viewHolder, int direction) {
  }
  
  public RecyclerviewSwipeHelper(SwipeActionInterface buttonsActions) {
      this.buttonsActions = buttonsActions;
  }
  /*
  @Override
  public float getSwipeEscapeVelocity(float defaultValue) {
      return 0.1f * defaultValue;
  }
  
  @Override
  public float getSwipeVelocityThreshold(float defaultValue) {
      return 5.0f * defaultValue;
  }
  
  @Override
  public float getSwipeThreshold(@NonNull RecyclerView.ViewHolder viewHolder) {
      return swipeTreshold;
  }
  */
  @Override
  public int convertToAbsoluteDirection(int flags, int layoutDirection) {
      if (swipeBack) {
          swipeBack = buttonShowedState != ButtonsState.GONE;
          return 0;
      }
      return super.convertToAbsoluteDirection(flags, layoutDirection);
  }
  
  public void onDraw(Canvas c) {
      if (currentItemViewHolder != null) {
      drawButtons(c, currentItemViewHolder);
      }
  }
  
  @Override
  public void onChildDraw(@NonNull Canvas c, @NonNull RecyclerView recyclerView, @NonNull RecyclerView.ViewHolder viewHolder, float dX, float dY, int actionState, boolean isCurrentlyActive) {
      if (actionState == ItemTouchHelper.ACTION_STATE_SWIPE) {
          if (buttonShowedState != ButtonsState.GONE) {
              if (buttonShowedState == ButtonsState.LEFT_VISIBLE)
                  dX = Math.max(dX, buttonWidth);
              if (buttonShowedState == ButtonsState.RIGHT_VISIBLE)
                  dX = Math.min(dX, -buttonWidth);
              super.onChildDraw(c, recyclerView, viewHolder, dX, dY, actionState, isCurrentlyActive);
          } else {
              setTouchListner(c, recyclerView, viewHolder, dX, dY, actionState, isCurrentlyActive);
          }
      }
  
      if (buttonShowedState == ButtonsState.GONE) {
          super.onChildDraw(c, recyclerView, viewHolder, dX, dY, actionState, isCurrentlyActive);
      }
      currentItemViewHolder = viewHolder;
     // drawButtons(c, viewHolder);
  }
  
  //Button의 모양
  private void drawButtons(Canvas c, RecyclerView.ViewHolder viewHolder) {
      float buttonWidthWithoutPadding = buttonWidth - 10;
      float corners = 5;
  
      View itemView = viewHolder.itemView;
      Paint p = new Paint();
  
  
      buttonInstance = null;
      if (buttonShowedState == ButtonsState.LEFT_VISIBLE) {
  
          RectF leftButton = new RectF(itemView.getLeft(), itemView.getTop(), itemView.getLeft() + buttonWidthWithoutPadding, itemView.getBottom());
          p.setColor(Color.BLUE);
          c.drawRoundRect(leftButton, corners, corners, p);
          drawText("EDIT", c, leftButton, p);
  
  
          buttonInstance = leftButton;
      } else if (buttonShowedState == ButtonsState.RIGHT_VISIBLE) {
          RectF rightButton = new RectF(itemView.getRight() - buttonWidthWithoutPadding, itemView.getTop(), itemView.getRight(), itemView.getBottom());
          p.setColor(Color.RED);
          c.drawRoundRect(rightButton, corners, corners, p);
          drawText("DELETE", c, rightButton, p);
  
          buttonInstance = rightButton;
      }
  }
  
  private void drawText(String text, Canvas c, RectF button, Paint p) {
      float textSize = 60;
      p.setColor(Color.WHITE);
      p.setAntiAlias(true);
      p.setTextSize(textSize);
  
      float textWidth = p.measureText(text);
      c.drawText(text, button.centerX() - (textWidth / 2), button.centerY() + (textSize / 2), p);
  }
  
  @SuppressLint("ClickableViewAccessibility")
  private void setTouchListner(final Canvas c, final RecyclerView recyclerView, final RecyclerView.ViewHolder viewHolder, final float dX, final float dY, final int actionState, final boolean isCurrentlyActive) {
  
      recyclerView.setOnTouchListener(new View.OnTouchListener() {
          @Override
          public boolean onTouch(View v, MotionEvent event) {
              swipeBack = event.getAction() == MotionEvent.ACTION_CANCEL || event.getAction() == MotionEvent.ACTION_UP;
              if (swipeBack) {
                  if (dX &lt; -buttonWidth) buttonShowedState = ButtonsState.RIGHT_VISIBLE;
                  else if (dX &gt; buttonWidth) buttonShowedState = ButtonsState.LEFT_VISIBLE;
  
                  if (buttonShowedState != ButtonsState.GONE) {
                      setTouchDownListener(c, recyclerView, viewHolder, dX, dY, actionState, isCurrentlyActive);
                      setItemsClickable(recyclerView, false);
                  }
              }
              return false;
          }
      });
  }
  
  @SuppressLint("ClickableViewAccessibility")
  private void setTouchDownListener(final Canvas c, final RecyclerView recyclerView, final RecyclerView.ViewHolder viewHolder, final float dX, final float dY, final int actionState, final boolean isCurrentlyActive) {
  
      recyclerView.setOnTouchListener(new View.OnTouchListener() {
          @Override
          public boolean onTouch(View v, MotionEvent event) {
              if (event.getAction() == MotionEvent.ACTION_DOWN) {
                  setTouchUpListener(c, recyclerView, viewHolder, dX, dY, actionState, isCurrentlyActive);
              }
              return false;
          }
      });
  }
  
  @SuppressLint("ClickableViewAccessibility")
  private void setTouchUpListener(final Canvas c, final RecyclerView recyclerView, final RecyclerView.ViewHolder viewHolder, final float dX, final float dY, final int actionState, final boolean isCurrentlyActive) {
      recyclerView.setOnTouchListener(new View.OnTouchListener() {
          @Override
          public boolean onTouch(View v, MotionEvent event) {
              if (event.getAction() == MotionEvent.ACTION_UP) {
                  RecyclerviewSwipeHelper.super.onChildDraw(c, recyclerView, viewHolder, 0F, dY, actionState, isCurrentlyActive);
                  recyclerView.setOnTouchListener(new View.OnTouchListener() {
                      @Override
                      public boolean onTouch(View v, MotionEvent event) {
  
                          return false;
                      }
                  });
                  setItemsClickable(recyclerView, true);
                  swipeBack = false;
                  if (buttonsActions != null &amp;&amp; buttonInstance != null &amp;&amp; buttonInstance.contains(event.getX(), event.getY())) {
                      if (buttonShowedState == ButtonsState.LEFT_VISIBLE) {
                          buttonsActions.onLeftClicked(viewHolder, viewHolder.getAdapterPosition());
                      } else if (buttonShowedState == ButtonsState.RIGHT_VISIBLE) {
                          buttonsActions.onRightClicked(viewHolder, viewHolder.getAdapterPosition());
                      }
                  }
                  buttonShowedState = ButtonsState.GONE;
                  currentItemViewHolder = null;
              }
              return false;
          }
      });
  }
  
  private void setItemsClickable(RecyclerView recyclerView, boolean isClickable) {
      for (int i = 0; i &lt; recyclerView.getChildCount(); ++i) {
          recyclerView.getChildAt(i).setClickable(isClickable);
      }
  }
  </code></pre>
  
  <p>And Part of Main Code</p>
  
  <pre><code> public void setupSwipe(){
      recyclerviewSwipeHelper = new RecyclerviewSwipeHelper(new SwipeActionInterface() {
          @Override
          public void onRightClicked(RecyclerView.ViewHolder viewHolder, int position) {
              long click_primaryKey = (long)viewHolder.itemView.getTag();
              temporaryStoreData = new TemporaryStoreData();
              final TemporaryStoreData temp = temporaryStoreData.recoverDataMethod(mDatabase, click_primaryKey);
              removeItem(click_primaryKey);
              recyclerAdapter.notifyItemRemoved(position);
              Snackbar.make(recyclerView, "이거고쳐야함", Snackbar.LENGTH_LONG)
                      .setAction("Undo", new View.OnClickListener() {
                          @Override
                          public void onClick(View v) {
                              ContentValues cv = temporaryStoreData.undoDataContentValue(temp);
                              if(mDatabase.insert(LSSQLContract.LocationTable.TABLE_NAME, null, cv) &gt; 0) {
                                  recyclerAdapter.swapCursor(databaseSortingQueryMethod(sortingCondition));
                                  Toast.makeText(getApplicationContext(), "Undo Success", Toast.LENGTH_SHORT).show();
                              }
                          }
                      }).show();
          }
          @Override
          public void onLeftClicked(RecyclerView.ViewHolder viewHolder, int position) {
              Snackbar.make(recyclerView, "일정에 추가되었습니다", Snackbar.LENGTH_LONG)
                      .setAction("Undo", new View.OnClickListener() {
                          @Override
                          public void onClick(View v) {
                              Toast.makeText(getApplicationContext(),"취소되었습니다",Toast.LENGTH_SHORT).show();
                          }
                      }).show();
          }
      });
  
      ItemTouchHelper itemTouchHelper = new ItemTouchHelper(recyclerviewSwipeHelper);
      itemTouchHelper.attachToRecyclerView(recyclerView);
  
      recyclerView.addItemDecoration(new RecyclerView.ItemDecoration() {
          @Override
          public void onDraw(@NonNull Canvas c, @NonNull RecyclerView parent, @NonNull RecyclerView.State state) {
              recyclerviewSwipeHelper.onDraw(c);
          }
      });
  }
  </code></pre>
  
  <p>Plz help me </p>