I have a RecyclerView row layout similar to this
<Layout> <BackgroundView> <ForegroundView> </Layout>
I use ItemTouchHelper to handle clicks (partial) in the foreground view, e.g.
@Override public void onSwiped(RecyclerView.ViewHolder viewHolder, int direction) { adapter.onItemSwiped(viewHolder); } @Override public void onChildDraw(Canvas c, RecyclerView recyclerView, RecyclerView.ViewHolder viewHolder, float dX, float dY, int actionState, boolean isCurrentlyActive) { View foregroundView = ((myViewHolder)viewHolder).getForegroundView(); getDefaultUIUtil().onDraw(c, recyclerView, foregroundView, dX, dY, actionState, isCurrentlyActive);
I set the click listener for backgroundview in the BindViewHolder my adapter class.
@Override public void onBindViewHolder(WhiteListViewHolder holder, Cursor cursor) { //get name and number from the cursor here holder.name.setText(name); holder.number.setText(number); holder.deleteButton.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View view) { Log.d("whitelist", "yes clicked"); } }); }
The problem is that the background view accepts clicks when the view does not scroll, but after the view is displayed, the background view stops accepting clicks.

Referring to the above image, if I click the delete button, the swiped view is sometimes restored and it does not capture the click.
If I let go of the whole view by clicking on the remaining empty space, you will also return the view you are viewing.
Thanks in advance.
android android-recyclerview
AMK
source share