4

I create a RecyclerView like following:

recyclerView.setLayoutManager(new GridLayoutManager(getContext(), cols, LinearLayoutManager.VERTICAL, stickToBottom);
recyclerView.setAdapter(adapter);

// completely disable animations... just to test if this solves the problem
recyclerView.setItemAnimator(null);

I long press a icon and start scrolling and sometimes, this results in recycled views looking pressed... I'm using a simple "android:background="?android:attr/selectableItemBackground" on my recyclerview items.

How can I solve the problem or what can be the root cause of this?

some facts

  • recycling views works perfectly, texts and images update as they should
  • ONLY the backgrounds are not resettet and look pressed even if the item is not touched...
  • I'm using the RecyclerView in the WindowManager not in an activity..
prom85
  • 16,896
  • 17
  • 122
  • 242

1 Answers1

0

Create a drawable

<selector xmlns:android="http://schemas.android.com/apk/res/android">

    <item android:state_pressed="false" android:drawable="@color/white" />
    <item android:state_pressed="true" android:drawable="@color/highlight_color" />

</selector>

Set this drawable to row_layout which you have used. It will work.

Akshay Mukadam
  • 2,388
  • 1
  • 27
  • 40
  • I tried a drawable without animations as well already... and it does not solve the problem. I had the idea, that the animations in the selector make problems... – prom85 Sep 14 '15 at 08:17
  • @prom85 It worked for me. I did the drag and Drop functionality with this and other stuff for RecyclerView – Akshay Mukadam Sep 14 '15 at 08:18