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
92
votes
22 answers

App crashing when trying to use RecyclerView on android 5.0

I'm trying to mess with the new RecyclerView and whenever I try to run it, my app immediately crashes. It gives me NullPointerException for trying to access methods from android.support.v7.widget.RecyclerView. I've looked at other posts and saw that…
Joe
  • 1,954
  • 5
  • 16
  • 22
91
votes
12 answers

How to know whether a RecyclerView / LinearLayoutManager is scrolled to top or bottom?

Currently I am using the follow code to check whether SwipeRefreshLayout should be enabled. private void laySwipeToggle() { if (mRecyclerView.getChildCount() == 0 || mRecyclerView.getChildAt(0).getTop() == 0) { …
Saren Arterius
  • 1,330
  • 1
  • 11
  • 15
91
votes
14 answers

Equivalent of ListView.setEmptyView in RecyclerView

In RecyclerView, I want to set an empty view to be shown when the adapter is empty. Is there an equivalent of ListView.setEmptyView()?
Manish Mulimani
  • 17,535
  • 2
  • 41
  • 60
91
votes
22 answers

How to import RecyclerView for Android L-preview

Trying to use the new RecyclerView from the support library. I downloaded the 20 update for the support library using the SDK manager. I've added the jar file to the libs folder - and added to build path - no luck using the RecyclerView. Tried to…
micnoy
  • 3,926
  • 4
  • 24
  • 27
87
votes
2 answers

Android setOnScrollListener on RecyclerView deprecated

setOnScrollListener is deprecated. Reading the docs from here it tells to Use addOnScrollListener(OnScrollListener) and removeOnScrollListener(OnScrollListener). What is the proper way to add and remove OnScrollListener? Do i need to use…
Kushal Sharma
  • 5,978
  • 5
  • 25
  • 41
86
votes
10 answers

onCheckedChanged called automatically

I have a switch in a recyclerview and data is displayed in the recyclerview after retrieving data from DB. When the recyclerview is opened I read DB and if a field in DB is "Y" I enable the switch or else I disable the switch. Now the problem is…
85
votes
11 answers

How to hide an item from Recycler View on a particular condition?

I am using Firebase Recycler Adapter (Firebase UI Library) to populate Recycler View. I want to hide an item(row) on a condition. I have a LinearLayout containing a recycler view. I set linear layout visibility to Gone in populateViewHolder()…
84
votes
11 answers

How to prevent RecyclerView item from blinking after notifyItemChanged(pos)?

I currently have a recycler view whose data updates every 5 secs. To update the data on the list, I am using notifyItemChanged(position); notifyItemRangeChanged(position, mList.size()); Each time I call notifyItemChanged(), the items on my…
portfoliobuilder
  • 7,556
  • 14
  • 76
  • 136
84
votes
8 answers

Why is adding an OnClickListener inside onBindViewHolder of a RecyclerView.Adapter considered bad practice?

I have the following code for a RecyclerView.Adapter class and it works fine: public class MyAdapter extends RecyclerView.Adapter { private List items; private int itemLayout; public…
Sujit Yadav
  • 2,697
  • 1
  • 15
  • 17
84
votes
6 answers

RecyclerView scrolled UP/DOWN listener

How do we know if user scrolled down or up in RecyclerView ? I tried with RecyclerView#OnScrollListener , it gives the amount of vertical scroll and the scroll state. How do we get the last scroll position when started to dragging and scrolled…
Libin
  • 16,967
  • 7
  • 61
  • 83
84
votes
9 answers

RecyclerView store / restore state between activities

I'm migrating my ListViews to RecyclerViews. With listviews I used the common technique described here to store and restore scroll position between activities. How to do the same with RecyclerViews? the RecyclerView.onSaveInstanceState() seem to…
khusrav
  • 5,267
  • 5
  • 27
  • 38
83
votes
23 answers

Changing background color of selected item in recyclerview

How to change the background color of only selected view in my recycle view example?only the background color of clicked itemview needs to be changed. Only one selected item must be displayed with background color change at a time and the rest needs…
c0der
  • 2,751
  • 2
  • 14
  • 21
83
votes
7 answers

Previewing horizontal recyclerview in android studio

I found out how to preview a list item by using tools:listitem="@layout/my_item_layout" Android studio however is previewing the recyclerview as a vertical list. Is there a way to tell Android Studio to display the layout preview in a horizontal…
fedepaol
  • 6,834
  • 3
  • 27
  • 34
83
votes
3 answers

What difference between static and non static viewholder in RecyclerView Adapter?

What are the advantages of this approach (using static nested class in my class MyAdapter extends RecyclerView.Adapter): static class MyVH extends RecyclerView.ViewHolder {...} And this approach (using member inner class): class MyVH extends…
Lester
  • 2,544
  • 4
  • 27
  • 38
83
votes
11 answers

How to center items of a recyclerview?

I need to center elements in each row so they will be like in this mockup. I've been searching if there is any layout that works that way without look. items are centered in their rows. This is how it looks now in my code.
Chris Gomez
  • 6,644
  • 4
  • 18
  • 39