Category Archives: RecyclerView

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

In the RecyclerView model, several different components work together to display your data. The overall container for your user interface is a RecyclerView object that you add to your layout. The RecyclerView fills itself with views provided by a layout manager that you provide. You can use one of our standard layout managers (such as LinearLayoutManager or GridLayoutManager), or implement your own.

The views in the list are represented by view holder objects. These objects are instances of a class you define by extending RecyclerView.ViewHolder. Each view holder is in charge of displaying a single item with a view. For example, if your list shows music collection, each view holder might represent a single album. The RecyclerView creates only as many view holders as are needed to display the on-screen portion of the dynamic content, plus a few extra. As the user scrolls through the list, the RecyclerView takes the off-screen views and rebinds them to the data which is scrolling onto the screen.

The view holder objects are managed by an adapter, which you create by extending RecyclerView.Adapter. The adapter creates view holders as needed. The adapter also binds the view holders to their data. It does this by assigning the view holder to a position, and calling the adapter’s onBindViewHolder() method. That method uses the view holder’s position to determine what the contents should be, based on its list position.

This RecyclerView model does a lot of optimization work so you don’t have to:
  • When the list is first populated, it creates and binds some view holders on either side of the list. For example, if the view is displaying list positions 0 through 9, the RecyclerView creates and binds those view holders, and might also create and bind the view holder for position 10. That way, if the user scrolls the list, the next element is ready to display.
  • As the user scrolls the list, the RecyclerView creates new view holders as necessary. It also saves the view holders which have scrolled off-screen, so they can be reused. If the user switches the direction they were scrolling, the view holders which were scrolled off the screen can be brought right back. On the other hand, if the user keeps scrolling in the same direction, the view holders which have been off-screen the longest can be re-bound to new data. The view holder does not need to be created or have its view inflated; instead, the app just updates the view’s contents to match the new item it was bound to.
  • When the displayed items change, you can notify the adapter by calling an appropriate RecyclerView.Adapter.notify…() method. The adapter’s built-in code then rebinds just the affected items.

Source: RecyclerView

RecyclerView – Swipe+delete and reorder items

In this chapter of the RecyclerView andorid tutorial we are going to implement how we can swipe+delete and reorder items inside of the list.

It means, when we swipe the item to the left or to the right, then this item gonna be deleted. When we tap the item a bit longer, then the item will be transparent, and we can move it everywhere inside the list.

Continue reading RecyclerView – Swipe+delete and reorder items

Follow and like us:

RecyclerView – The FloatingActionButtons

In this chapter of the RecyclerView Andorid tutorial we are going to add actions and animations for the FloatingActionButtons. It means, when we click on the FAB, then 2 more FABs will be visible. They are the buttons to open the bottom sheet of searchand  the dialog to add a new ToDo.

Our user interface already contains the FABs. So, what we will do in this chapter is the definition of the distance of the upwards move, then the animation, and finally the click listener to open the dialogs.

So, let’s start coding! 😎 Continue reading RecyclerView – The FloatingActionButtons

Follow and like us:

RecyclerView – Search and filter

In this chapter of the RecyclerView andorid tutorial we are going to implement how we can search in the titles of the items, which means we gonna implement a filter function.

First in this chapter, we are going to create a new fragment. This fragment will be a BottomSheetDialogFragment. It means, when we click on the Search FloatingActionButton, then the fragment slides up with the search fields.

Continue reading RecyclerView – Search and filter

Follow and like us:

RecyclerView – Add new items

In this chapter of the RecyclerView Andorid tutorial we are going to add new items to the list. Our application already contains the RecyclerView, the action buttons, and the user interface of the dailog, where we can add the detailes of the new ToDo item.

In the very last chapter (Adapter + ViewHolder) we have created the adapter, which handels the items of the list. We have created the view holder as well. The view holder’s task is to set the itemss’ values and to handle the click listeneres.

We are going to add the action for the Send button. This will call a method inside of the viewmodel, which will update the list and the RecyclerView, that a new item had been inserted.

So let’s start coding. 😎

Continue reading RecyclerView – Add new items

Follow and like us:

RecyclerView – Modify item

In this chapter of the RecyclerView andorid tutorial we are going to implement how we can modify an item of the list. When we the tap an item, then the same dialog will popup, what we can use to create a new item.

In this case, the dialog will be filled out with the data of the clicked item, and the action button of Modify will change the properties of the item and notify the RecyclerView about the change.

Continue reading RecyclerView – Modify item

Follow and like us:

RecyclerView – Adapter + ViewHolder

In this chapter of the RecyclerView andorid tutorial we are going to add to the project the Adapter  of the RecyclerView and the ViewHolder of the items. The Adapter is responsible for providing view that represent items in a data set. The ViewHolder reprents the views in the list. Each ViewHolder is in charge of displaying a single item with a view.

Continue reading RecyclerView – Adapter + ViewHolder

Follow and like us: