简体   繁体   中英

Interaction with locked ViewHolder in RecyclerView using ItemTouchHelper

I'm using a custom ItemTouchListener to make my items in a RecyclerView swipeable. The ViewHolders have a RelativeLayout so when I'm swiping them left a pair of Buttons appear. But now my problem is that my Buttons are not clickable at the first touch after the swipe. I need to click the ViewHolder 3 times so i can interact with it again (clicking buttons, edit textviews).

In my custom ItemTouchHelper onChildDraw method I'm doing something like this to keep the ViewHolder at a specific position and make the buttons under the swipeable view visible:

if(dX > itemView.getWidth() / 4){
    dX = itemView.getWidth() / 4;
}
((CustomViewHolder) viewHolder).getSwipeAbleLayout().setTranslationX(dX);

It seems like the ViewHolder is still in swipe mode during the first two clicks.

Or does someone have a better solution to lock a ViewHolder at a specific position while swiping so that buttons appear which can be clicked to either remove the ViewHolder or swipe the ViewHolder back to normal position?

Consider using this github project - itemtouchhelper-extension . I got my all problem solved using that in my recent project. Its is having pretty good implmenation example as well. Try out.

I solved my problem by using following library: AndroidSwipeLayout

It is pretty simple to use. Can recommend it to everyone who needs to work with "locked RecyclerView items".

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM