title: Undo swipe in recycler view on pressing back button?
body: <p>How to restore the swiped view on pressing back button in recyclerView ? </p>
  
  <p>MY CODE</p>
  
  <p>RecyclerListAdapter.java</p>
  
  <pre><code>public class RecyclerListAdapter extends RecyclerView.Adapter&lt;RecyclerListAdapter.ItemViewHolder&gt;
          implements ItemTouchHelperAdapter {
  
  
      private final List&lt;Card&gt; mItems = new ArrayList&lt;&gt;();
  
      Card car1 = new Card(R.drawable.card1, "Text First");
      Card car2 = new Card(R.drawable.card1, "Text Second");
      Card car3 = new Card(R.drawable.card3, "Text First");
      Card car4 = new Card(R.drawable.card4, "Text Second");
      Card car5 = new Card(R.drawable.card3, "Text First");
      Card car6 = new Card(R.drawable.card2, "Text Second");
  
      public RecyclerListAdapter() {
          mItems.addAll(Arrays.asList(car1, car2,car3,car4,car5,car6));
      }
  
      @Override
      public ItemViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
          View view = LayoutInflater.from(parent.getContext()).inflate(R.layout.card, parent, false);
          ItemViewHolder itemViewHolder = new ItemViewHolder(view);
          return itemViewHolder;
      }
  
      @Override
      public void onBindViewHolder(ItemViewHolder holder, int position) {
          final Card card = mItems.get(position);
          holder.textView.setText(card.getText());
          holder.imageView.setImageResource(card.getImage());
  
      }
  
      @Override
      public void onItemDismiss(int position) {
  
          mItems.remove(position);
          notifyItemRemoved(position);
      }
  
      @Override
      public void onItemMove(int fromPosition, int toPosition) {
          Card prev = mItems.remove(fromPosition);
          mItems.add(toPosition &gt; fromPosition ? toPosition - 1 : toPosition, prev);
          notifyItemMoved(fromPosition, toPosition);
      }
  
      @Override
      public int getItemCount() {
          return mItems.size();
      }
  
  
      public static class ItemViewHolder extends RecyclerView.ViewHolder implements
              ItemTouchHelperViewHolder {
  
          public final TextView textView;
          public final ImageView imageView;
  
          public ItemViewHolder(View itemView) {
              super(itemView);
              textView = (TextView) itemView.findViewById(R.id.heading_text);
              imageView= (ImageView)itemView.findViewById(R.id.image);
  
          }
  
          @Override
          public void onItemSelected() {
              itemView.setBackgroundColor(Color.LTGRAY);
          }
  
          @Override
          public void onItemClear() {
              itemView.setBackgroundColor(0);
          }
      }
  }
  </code></pre>
  
  <p>SimpleItemTouchHelperCallback.java</p>
  
  <pre><code>public class SimpleItemTouchHelperCallback extends ItemTouchHelper.Callback {
  
      private final ItemTouchHelperAdapter mAdapter;
  
      public SimpleItemTouchHelperCallback(ItemTouchHelperAdapter mAdapter) {
          this.mAdapter = mAdapter;
      }
  
      @Override
      public boolean isLongPressDragEnabled() {
          return false;
      }
  
      @Override
      public boolean isItemViewSwipeEnabled() {
          return true;
      }
  
  
      @Override
      public int getMovementFlags(RecyclerView recyclerView, RecyclerView.ViewHolder viewHolder) {
          int dragFlags = 0;
          int swipeFlags = ItemTouchHelper.END;
          return makeMovementFlags(dragFlags, swipeFlags);
      }
  
      @Override
      public boolean onMove(RecyclerView recyclerView, RecyclerView.ViewHolder viewHolder, RecyclerView.ViewHolder target) {
          mAdapter.onItemMove(viewHolder.getAdapterPosition(), target.getAdapterPosition());
          return true;
      }
  
      @Override
      public void onSwiped(RecyclerView.ViewHolder viewHolder, int direction) {
          mAdapter.onItemDismiss(viewHolder.getAdapterPosition());
  
      }
  
  
      public void onSelectedChange(RecyclerView.ViewHolder viewHolder, int actionstate) {
          if (actionstate != ItemTouchHelper.ACTION_STATE_IDLE) {
              ItemTouchHelperViewHolder itemViewHolder = (ItemTouchHelperViewHolder) viewHolder;
              itemViewHolder.onItemSelected();
          }
          super.onSelectedChanged(viewHolder, actionstate);
      }
      @Override
      public void clearView(RecyclerView recyclerView,RecyclerView.ViewHolder viewHolder){
          super.clearView(recyclerView,viewHolder);
  
          ItemTouchHelperViewHolder itemViewHolder =  (ItemTouchHelperViewHolder) viewHolder;
          itemViewHolder.onItemClear();
      }
  }
  </code></pre>
  
  <p>ItemTouchHelperAdapter.java</p>
  
  <pre><code>public interface ItemTouchHelperAdapter {
  void onItemMove(int fromPosition, int toPosition);
  void onItemDismiss(int position);
  }
  </code></pre>
  
  <p>ItemTouchHelperViewHolder.java</p>
  
  <pre><code>public interface ItemTouchHelperViewHolder {
   void onItemSelected();
     void onItemClear();
  
  }
  </code></pre>
  
  <p>Everything works fine but i need to know how to get the swiped view back on pressing back button.</p>