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
79
votes
8 answers

GridLayoutManager - how to auto fit columns?

I have a RecyclerView with a GridLayoutManager that displays Card Views. I want the cards to rearrange according to the screen size (the Google Play app does this kind of thing with its app cards). Here is an example: Here is how my app looks at…
79
votes
12 answers

Android RecyclerView ItemTouchHelper revert swipe and restore view holder

Is there a way to revert a swipe action and restore the view holder to its initial position after the swipe is completed and onSwiped is called on the ItemTouchHelper.Callback instance? I got the RecyclerView, ItemTouchHelper and…
kukabi
  • 1,273
  • 1
  • 9
  • 14
77
votes
1 answer

getAdapterPosition() is deprecated

I've updated my targetSdkVersion from 28 to 30 and I've noticed that getAdapterPosition() is deprecated (I'm not sure when this happened). In the documentation, they say the following: This method is deprecated. This method is confusing when…
ClassA
  • 2,480
  • 1
  • 26
  • 57
77
votes
11 answers

How to add a fast-scroller to the RecyclerView

Background On ListView, you could have a fast scroller which allowed you to drag a scrollbar to easily scroll to wherever you wished (using fastScrollEnabled attribute) Together with "SectionIndexer" class and optionally some attributes, you could…
android developer
  • 114,585
  • 152
  • 739
  • 1,270
76
votes
4 answers

Need an example about RecyclerView.Adapter.notifyItemChanged(int position, Object payload)

According to RecyclerView documentation about medthod notifyItemChanged(int position, Object payload) Notify any registered observers that the item at position has changed with an optional payload object. I don't understand how to use second…
76
votes
4 answers

Best way to update data with a RecyclerView adapter

When I have to use a classic adapter with a ListView, I update my data in the ListView like this: myAdapter.swapArray(data); public swapArray(List data) { clear(); addAll(data); notifyDataSetChanged(); } I would like to know what is…
Alex DG
  • 1,859
  • 2
  • 22
  • 34
75
votes
4 answers

Android - Swipe to delete RecyclerView

I am trying to implement swipe to delete the same as Gmail app "Swipe to archive": I have tried many tutorials but none of them works as fast as gmail, I prefer to not work on external library. How can i do it? Edit: My code so far- …
Montoya
  • 2,819
  • 3
  • 37
  • 65
75
votes
8 answers

When switch fragment with SwipeRefreshLayout during refreshing, fragment freezes but actually still work

UPDATE: I thought it worked correctly. But after some test trouble still exists *sniff* Then I made a simpler version to see what exactly happen and I get to know that the refreshing fragment which should have been detached still left there. Or…
75
votes
9 answers

Square layout on GridLayoutManager for RecyclerView

I try to make a grid-layout with square images. I thought that it must be possible to manipulate the GridLayoutManager by manipulating onMeasure to do a super.onMeasure(recycler, state, widthSpec, widthSpec); instead of super.onMeasure(recycler,…
Paul Woitaschek
  • 6,717
  • 5
  • 33
  • 52
74
votes
12 answers

Margin between items in recycler view Android

Hi I am Following this tutorial: http://www.journaldev.com/10024/android-recyclerview-and-cardview-example-tutorial Now I am facing a weird issue the margin between each CardView item inside RecyclerView is way too much. ISSUE How to reduce…
Tushar Narang
  • 1,997
  • 3
  • 21
  • 49
74
votes
7 answers

Override animation for notifyItemChanged in RecyclerView.Adapter

Well, I have a RecyclerView with an adapter and everything works great. The items in the ArrayList dataset are being updated periodically. So the items and their elements as well as their position in the list change. This is achieved by simple…
Alex
  • 1,395
  • 1
  • 13
  • 22
74
votes
13 answers

Snappy scrolling in RecyclerView

I am trying to use the new RecyclerView class for a scenario where I want the component to snap to a specific element when scrolling (The old Android Gallery comes to mind as an example of such a list with a center-locked item). This is the…
Catherine
  • 13,588
  • 9
  • 39
  • 60
73
votes
14 answers

Android Horizontal RecyclerView scroll Direction

I made a Horizontal RecyclerView and it works fine(thanks to this) but the direction of scroll and data are expand from left to right; then How can I change the RecyclerView scroll direction like in the picture below? My…
Hamid Goodarzi
  • 1,364
  • 2
  • 13
  • 22
73
votes
5 answers

How to implement multi-select in RecyclerView?

I'm trying to implement a RecyclerView with multiple selectable items. Here is what I've tried but I couldn't make it work. This is what I'm trying to do:
Hegdekar
  • 1,147
  • 1
  • 13
  • 16
73
votes
13 answers

How do I get the position selected in a RecyclerView?

I am experimenting with the support library's recyclerview and cards. I have a recyclerview of cards. Each card has an 'x' icon at the top right corner to remove it: The card xml, list_item.xml: