RecyclerView Swipe with the following view, not detecting a click

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); //getSwipeLimit() used below returns the width of the delete icon float translationX = Math.min(-dX, ((myViewHolder) viewHolder).getSwipeLimit()); foregroundView.setTranslationX(-translationX); } 

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.

enter image description here

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.

+8
android android-recyclerview
source share
1 answer

I solved the first part of the problem - now I did not find it without a napkin. But the click does not detect after scrolling ...

  @Override public void onChildDraw(Canvas c, RecyclerView recyclerView, RecyclerView.ViewHolder viewHolder, float dX, float dY, int actionState, boolean isCurrentlyActive) { if(actionState == ItemTouchHelper.ACTION_STATE_SWIPE){ if (dX < 0) { backgroundView.setVisibility(View.VISIBLE); } else { backgroundView.setVisibility(View.GONE); } } } 
0
source share

All Articles