Questions tagged [android-recyclerview]

The RecyclerView widget is a more advanced and flexible version of ListView and GridView.

The RecyclerView widget is a more advanced and flexible version of ListView and GridView. This widget is a container for displaying large datasets that can be scrolled very efficiently by maintaining a limited number of views. Use the RecyclerView widget when you have data collections whose elements change at runtime based on user action or network events.

• See how to create a list with RecyclerView.


RecyclerApdater Adapter optimized for RecyclerView

The RecyclerView class simplifies the display and handling of large data sets by providing:

  1. Layout Managers for positioning items
  2. Default animations for common item operations, such as removal or addition of items

enter image description here

Tag Usage:

29237 questions
128
votes
9 answers

Using Espresso to click view inside RecyclerView item

How can I use Espresso to click a specific view inside a RecyclerView item? I know I can click the item at position 0 using: onView(withId(R.id.recyclerView)) .perform(RecyclerViewActions.actionOnItemAtPosition(0, click())); But I need to click on a…
Filipe Ramos
  • 1,755
  • 2
  • 18
  • 24
128
votes
10 answers

Recyclerview and handling different type of row inflation

I'm trying to work with the new RecyclerView, but I could not find an example of a RecyclerView with different types of rows/cardviews getting inflated. With ListView I override the getViewTypeCount and getItemViewType, for handling different types…
Lokkio
  • 1,703
  • 2
  • 16
  • 19
126
votes
14 answers

RecyclerView GridLayoutManager: how to auto-detect span count?

Using the new GridLayoutManager: https://developer.android.com/reference/android/support/v7/widget/GridLayoutManager.html It takes an explicit span count, so the problem now becomes: how do you know how many "spans" fit per row? This is a grid,…
125
votes
22 answers

Get clicked item and its position in RecyclerView

I am replacing my ListView with RecyclerView, list showing ok, but I would like to know how to get clicked item and its position, similar to the method OnItemClickListener.onItemClick(AdapterView parent, View v, int position, long id) we use in…
Xcihnegn
  • 11,579
  • 10
  • 33
  • 33
125
votes
6 answers

Is there any way to enable scrollbars for RecyclerView in code?

As we saw, RecyclerView is more effective than ListView, so I prefer to use it in my project. But recently I have a trouble when put it in my custom ViewGroup. RecyclerView is easy to set scrollbars in xml like…
Kevin Liu
  • 1,603
  • 3
  • 11
  • 14
119
votes
7 answers

Disable Swipe for position in RecyclerView using ItemTouchHelper.SimpleCallback

I am using recyclerview 22.2.0 and the helper class ItemTouchHelper.SimpleCallback to enable swipe-to-dismiss option to my list. But as I have a type of header on it, I need to disable the swipe behavior for the first position of the adapter. As…
Rafael Toledo
  • 5,599
  • 6
  • 23
  • 33
119
votes
5 answers

Swipe to Dismiss for RecyclerView

I used to SwipeToDismiss library but now I'm trying to migrate to RecyclerView and things are not so obvious, do you know any replacements for this lib? Any ideas how to implement it from the scratch?
Viktor Yakunin
  • 2,927
  • 3
  • 24
  • 39
119
votes
28 answers

RecyclerView crashes when "scrapped or attached views may not be recycled"

I'm using a simple implementation of RecyclerView taken from the Android website using a StaggeredGridLayoutManager and I keep getting this error that crashes my app: java.lang.IllegalArgumentException: Scrapped or attached views may not be…
StackOverflowMaster
  • 3,478
  • 3
  • 18
  • 19
116
votes
10 answers

Cannot call this method while RecyclerView is computing a layout or scrolling when try remove item from recyclerview

I am Trying to remove my item from recyclerview, but i always getting error java.lang.IllegalStateException: Cannot call this method while RecyclerView is computing a layout or scrolling i am using notify datasetchanged, can i solve…
Denny Kurniawan
  • 1,581
  • 2
  • 15
  • 28
113
votes
17 answers

RecyclerView remove divider / decorator after the last item

I have a quite simple RecyclerView. This is how I set the divider: DividerItemDecoration itemDecorator = new DividerItemDecoration(getContext(), DividerItemDecoration.VERTICAL); itemDecorator.setDrawable(ContextCompat.getDrawable(getActivity(),…
Slobodan Antonijević
  • 2,533
  • 2
  • 17
  • 27
113
votes
21 answers

How to create context menu for RecyclerView

How do I implement context menu for RecyclerView? Apparently calling registerForContextMenu(recyclerView) doesn't work. I'm calling it from a fragment. Did anybody have any success implementing this?
Binoy Babu
  • 16,699
  • 17
  • 91
  • 134
111
votes
13 answers

Android add spacing below last element in recyclerview with gridlayoutmanager

I am trying to add spacing below the last element row in RecyclerView with GridLayoutManager. I used custom ItemDecoration for this purpose with bottom padding when its last element as follows: public class SpaceItemDecoration extends…
pratsJ
  • 3,369
  • 3
  • 22
  • 41
110
votes
7 answers

RecyclerView horizontal scroll snap in center

I'm trying to make a carousel-like view here using RecyclerView, I want the item to snap in the middle of the screen when scrolling, one item at a time. I've tried using recyclerView.setScrollingTouchSlop(RecyclerView.TOUCH_SLOP_PAGING); but the…
Ahmed Awad
  • 1,787
  • 3
  • 16
  • 22
108
votes
15 answers

Recycler View: Inconsistency detected. Invalid view holder adapter positionViewHolder

Recycler View Inconsistency Detected error, coming while scrolling fast or scrolling while loading more items.. FATAL EXCEPTION: main Process: com.pratap.endlessrecyclerview, PID: 21997 java.lang.IndexOutOfBoundsException: Inconsistency detected.…
Prashanth
  • 1,309
  • 2
  • 9
  • 17
106
votes
17 answers

Saving EditText content in RecyclerView

I have list item with EditText in it, I don't know how many items there will be. I have a problem when I enter some text in EditText, and then scroll down a RecyclerView, after I've scroll up again there is no text in my first EditText. I am…
gatteo
  • 1,382
  • 2
  • 10
  • 17