1

I am having a list and if i swipe item will remove from the list but i want to add snackbar with UNDO button in the same position from where item removed from list like Gmail . I tried but every time my snackbar is coming at the top. I am using itemTouchHelper class and here is my onSwipe method

 public void onSwiped(final RecyclerView.ViewHolder viewHolder, int direction) {
    // Notify the adapter of the dismissal
   mAdapter.onItemDismiss(mRecyclerView,viewHolder,viewHolder.getAdapterPosition());

}

onItemDismiss Method

public void onItemDismiss(final RecyclerView mRecyclerView, final  RecyclerView.ViewHolder viewHolder, final int position) {

    final String mPhoto = mItems.get(position);
    Snackbar snackbar = Snackbar
            .make(mRecyclerView, "Item Deleted from list", Snackbar.LENGTH_LONG)
            .setAction("UNDO", new View.OnClickListener() {
                @Override
                public void onClick(View view) {
                    // mItems.(position);
                    //notifyItemInserted(position);
                    //recyclerView.scrollToPosition(position);
                    //mItems.remove(position);
                    mItems.add(position, mPhoto);
                    notifyItemInserted(position);
                    mRecyclerView.scrollToPosition(position);
                    PhotosToDelete.remove(mPhoto);
                }
            });
    View view = snackbar.getView();
    FrameLayout.LayoutParams params = (FrameLayout.LayoutParams)view.getLayoutParams();
    params.gravity = Gravity.AXIS_PULL_AFTER;
    view.setLayoutParams(params);
    snackbar.show();
    mItems.remove(position);
    notifyItemRemoved(position);
    PhotosToDelete.add(mPhoto);

}
Ritesh Mathur
  • 829
  • 2
  • 8
  • 17
  • What happens if you just create the Snackbar and call show(), without tinkering with the layout params manually? – Egor Jan 14 '16 at 08:57
  • i just want to adjust the position of snackbar means i don't want to remove item directly .first i want to set confirmation message with undo option using snackbar – Ritesh Mathur Jan 14 '16 at 09:01
  • Check [here](http://stackoverflow.com/a/31496283/4596556) – Madhukar Hebbar Jan 14 '16 at 09:08
  • Why you don't use Custom Toast ? you can position it – Amir Jan 14 '16 at 09:09
  • @Amir if i will use Custom Toast again the same problem .It's position i want to show at the same position from where item removed like gmail app inbox .How can i achieve this from toast – Ritesh Mathur Jan 14 '16 at 09:15
  • I don't think so any pre-build feature give this functionality , you should create your own layout. – Amir Jan 14 '16 at 09:23
  • @MadhukarHebbar this link is not working for me i tried to implemented this but snackbar is showing at the bottom – Ritesh Mathur Jan 14 '16 at 09:50

0 Answers0