Summary in few words
Below you can see what about your are going to learn in this course.
- Data class
- Navigation Component
- ViewModel + LiveData + MutableLiveData
- Add, modify and delete item
- Search and filter items
- Expandable Floating Action Buttons
The sample app
Our sample application will be a simple todo list application. In this app you can create, modify and delete the created todos.
After the creation you are going to see them in a RecyclerView, which uses a custom layout for the items.
Every item has a title, a due date, a description and a priority which is shown by a circle which has 3 states depending on the urgency of the todo.
The user interface contains a FloatingActionButton. By clicking on it 2 more FABs will be visible. With the first we can createa new todo, and second one is for searching todos in the RecyclerView items.
We can modify the todos as by clicking on the item. When we did it, then the same popup window will be visible which is able to create a new item as well.
This tutorial assumes, that you have already a basic knowledge about Android development. For this tutorial you should be familiar with the Kotlin programming language. The second thing is that, we will use for the fragment navigation the Jetpack Navigation Component library. If you still don’t know how to use it, then it is highly recommended to do our beginner tutorial.
The RecyclerView widget is a more advanced and flexible version of ListView.
In the RecyclerView model, several different components work together to display our data. The overall container for our user interface is a RecyclerView object that you add to our layout. The RecyclerView fills itself with views provided by a layout manager that we should provide. We can use one of the standard layout managers (such as LinearLayoutManager or GridLayoutManager), or implement own own manager.
The views in the list are represented by ViewHolder objects. These objects are instances of a class we define by extending RecyclerView.ViewHolder. Each view holder is in charge of displaying a single item with a view. For instance, if our list shows todos collection, each view holder might represent a single task. 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 we 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 we don’t have to:
- When the list is first time populated, it creates and binds some view holders on either side of the list. For instance, 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.
I hope the description was understandable and clear. But, if you have still questions, then leave me comments below! 😉
Have a nice a day! 🙂