title: RecyclerView ItemTouchHelper swipe undo
body: <p>I'm reveal the hidden view after swiping with 2 buttons "delete" and "cancel".
  in my xml itemrow i have 2 inner Relativelayouts </p>
  
  <pre><code>&lt;FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
  xmlns:tools="http://schemas.android.com/tools"
  android:layout_width="match_parent"
  android:layout_height="wrap_content"
  android:paddingBottom="10dp"
  android:paddingTop="10dp"&gt;
  
  &lt;include
      android:id="@+id/item_container"
      layout="@layout/layout_back" /&gt;
  
  &lt;RelativeLayout
      android:id="@+id/front"
      android:layout_width="match_parent"
      android:layout_height="match_parent"
      android:background="@drawable/quest_background_blue"
      android:orientation="horizontal"
      android:tag="front"
      android:focusableInTouchMode="true"&gt;
  
      &lt;ImageView
          android:id="@+id/icon"
          android:layout_width="wrap_content"
          android:layout_height="wrap_content"
  
          android:layout_alignParentLeft="true"
          android:layout_centerVertical="true"
          android:layout_gravity="center_vertical"
          android:padding="8dp" /&gt;
  
      &lt;include
          android:id="@+id/contprice"
          style="@style/wrap"
          layout="@layout/quest_price"
          android:layout_width="wrap_content"
          android:layout_height="wrap_content"
          android:layout_alignParentRight="true"
          android:layout_centerVertical="true" /&gt;
  
      &lt;LinearLayout
          style="@style/wrap.linear"
          android:layout_gravity="center_vertical"
          android:layout_toLeftOf="@id/contprice"
          android:layout_toRightOf="@id/icon"
          android:layout_weight="0.4"&gt;
  
          &lt;TextView
              android:id="@+id/title"
              style="@style/quest_title"
              android:text="Рассказать друзьям" /&gt;
  
          &lt;TextView
              android:id="@+id/details"
              style="@style/quest_detail" /&gt;
      &lt;/LinearLayout&gt;
  &lt;/RelativeLayout&gt;
  
  &lt;/FrameLayout&gt;
  </code></pre>
  
  <p>RelativeLayout with id front is swipeable, on included layout with id item_container where is two buttons</p>
  
  <pre><code>&lt;RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
              android:layout_width="match_parent"
              android:layout_height="match_parent"
              android:layout_centerVertical="true"
              android:background="@android:color/transparent"&gt;
  &lt;TextView
      android:id="@+id/cancel"
      android:textColor="#0eb0a0"
      android:layout_width="wrap_content"
      android:layout_height="match_parent"
      android:layout_alignParentRight="true"
      android:clickable="true"
      android:focusable="false"
      android:focusableInTouchMode="false"
      android:gravity="center"
      android:padding="10dp"
      android:text="Отмена"
      android:textStyle="bold"/&gt;
  
  &lt;TextView
      android:id="@+id/delete"
      android:textColor="#e6007e"
      android:layout_width="wrap_content"
      android:layout_height="match_parent"
      android:layout_alignParentLeft="true"
      android:clickable="true"
      android:focusable="false"
      android:focusableInTouchMode="false"
      android:gravity="center"
      android:padding="10dp"
      android:text="Скрыть"
      android:textStyle="bold"/&gt;
  &lt;/RelativeLayout&gt;
  </code></pre>
  
  <p>the problem is that when hidden layouts with buttons showed 
  buttons not clickable </p>
  
  <p>here ItemTouchHelper implementions </p>
  
  <pre><code>public class MyItemTouchHelper extends ItemTouchHelper.SimpleCallback {
  
  private ItemAdapter itemAdapter;
  private RecyclerView recyclerView;
  
  public MyItemTouchHelper(RecyclerView mRecyclerView, ItemAdapter itemAdapter) {
      super(0, ItemTouchHelper.START | ItemTouchHelper.END);
      this.itemAdapter = itemAdapter;
      this.recyclerView = mRecyclerView;
  }
  
  @Override
  public boolean onMove(RecyclerView recyclerView, RecyclerView.ViewHolder viewHolder, RecyclerView.ViewHolder target) {
      return false;
  }
  
  @Override
  public int getMovementFlags(RecyclerView recyclerView, RecyclerView.ViewHolder viewHolder) {
      int swipeFlags = ItemTouchHelper.START | ItemTouchHelper.END;
      return makeMovementFlags(0, swipeFlags);
  }
  
  @Override
  public boolean isItemViewSwipeEnabled() {
      return true;
  }
  
  @Override
  public void onSwiped(final RecyclerView.ViewHolder viewHolder, int direction) {
      Log.d("SWIPE", " direction = " + direction);
      final ItemAdapter.ItemViewHolder holder = (ItemAdapter.ItemViewHolder) viewHolder;
      holder.itemView.setOnClickListener(null);
      ((ItemAdapter.ItemViewHolder) viewHolder).itemContainer.bringToFront();
      ((ItemAdapter.ItemViewHolder) viewHolder).itemContainer.invalidate();
      ((ItemAdapter.ItemViewHolder) viewHolder).itemCancel.setEnabled(true);
      ((ItemAdapter.ItemViewHolder) viewHolder).itemDelete.setEnabled(true);
      ((ItemAdapter.ItemViewHolder) viewHolder).itemContainer.setVisibility(View.VISIBLE);
  
      ((ItemAdapter.ItemViewHolder) viewHolder).itemDelete.setOnClickListener(new View.OnClickListener() {
          @Override
          public void onClick(View v) {
              Toast.makeText(v.getContext(), "DELETE " + viewHolder.getAdapterPosition(), Toast.LENGTH_SHORT).show();
              itemAdapter.removeItem(viewHolder.getAdapterPosition());
              recyclerView.getAdapter().notifyItemRemoved(viewHolder.getAdapterPosition());
          }
      });
      ((ItemAdapter.ItemViewHolder) viewHolder).itemCancel.setOnClickListener(new View.OnClickListener() {
          @Override
          public void onClick(View v) {
              Toast.makeText(v.getContext(), "CANCEL " + viewHolder.getAdapterPosition(), Toast.LENGTH_SHORT).show();
              ((ItemAdapter.ItemViewHolder) viewHolder).itemContainer.setVisibility(View.INVISIBLE);
              holder.itemView.setOnClickListener(ItemAdapter.itemAdapterClickListener(viewHolder.getAdapterPosition()));
              recyclerView.getAdapter().notifyItemChanged(viewHolder.getAdapterPosition());
              clearView(recyclerView, viewHolder);
              ((ItemAdapter.ItemViewHolder) viewHolder).itemCancel.setEnabled(false);
              ((ItemAdapter.ItemViewHolder) viewHolder).itemDelete.setEnabled(false);
              ((ItemAdapter.ItemViewHolder) viewHolder).itemContext.setVisibility(View.VISIBLE);
              ((ItemAdapter.ItemViewHolder) viewHolder).itemContext.bringToFront();
              ((ItemAdapter.ItemViewHolder) viewHolder).itemContext.invalidate();
          }
      });
  }
  
  
  @Override
  public void onChildDraw(Canvas c, RecyclerView recyclerView, RecyclerView.ViewHolder viewHolder, float dX, float dY, int actionState, boolean isCurrentlyActive) {
      if (viewHolder.getAdapterPosition() == -1) {
          return;
      }
  
      ItemAdapter.ItemViewHolder holder = (ItemAdapter.ItemViewHolder) viewHolder;
      if (actionState == ItemTouchHelper.ACTION_STATE_SWIPE) {
          if (dX &gt; 0 || dX &lt; 0) {
              holder.itemContext.setTranslationX(dX);
  
          }
      } else {
          super.onChildDraw(c, recyclerView, viewHolder, dX, dY,
                  actionState, isCurrentlyActive);
      }
  }
  
  
  @Override
  public void clearView(RecyclerView recyclerView, RecyclerView.ViewHolder viewHolder) {
      super.clearView(recyclerView, viewHolder);
      View foreground = ((ItemAdapter.ItemViewHolder) viewHolder).getSwipableView();
      getDefaultUIUtil().clearView(foreground);
  }
  }
  </code></pre>
  
  <p>and here viewholder </p>
  
  <pre><code> public class ItemViewHolder extends RecyclerView.ViewHolder {
  
      TextView itemText;
      RelativeLayout itemContainer;
      RelativeLayout itemContext;
      TextView itemDelete;
      TextView itemCancel;
  
      public ItemViewHolder(View itemView) {
          super(itemView);
          itemText = (TextView) itemView.findViewById(R.id.details);
          itemDelete = (TextView) itemView.findViewById(R.id.delete);
          itemCancel = (TextView) itemView.findViewById(R.id.cancel);
          itemContainer = (RelativeLayout) itemView.findViewById(R.id.item_container);
          itemContext = (RelativeLayout) itemView.findViewById(R.id.front);
  
      }
  
      public ViewGroup getSwipableView() {
          return itemContext;
      }
  
      public ViewGroup getItemContainer() {
          return itemContainer;
      }
  }
  </code></pre>
  
  <p>if be more correct buttons clicks but not with first try
  UPDATE
  after swipe, then click on item its like still on swipe mode and by the log it's showing  thats first 3 clicks is swiping direction<br>
  onSwipe
  Log.d("SWIPE", " direction = " + direction);</p>
  
  <pre><code>D/SWIPE:  direction = 16
  D/SWIPE:  direction = 16
  D/SWIPE:  direction = 16
  </code></pre>
  
  <p>and after that clicks button cancel or delete</p>