Today i gonna show you how to working with Recyclerview. A simple tutorial in order to you are easy to understand.
In this tutorial you just need to create three java classes, there are :
And two xml layouts, there are :
First, compile the Recyclerview library on your build.gradle(Module:app), like the following :
Modify your activity_main.xml, like the following xml :
Next, create one more layout for the item, in this project named as item_user.xml :
Now, it's time to modify our java class, first we need to create a model for our user. In this project named UserModel.java
Second, we modify UserAdapter.java, this adapter have to extend RecyclerView.Adapter<>. But before do that, the first thing you should do is write the inner class and give name as ViewHolder and this inner class extends RecyclerView.ViewHolder. So the UserAdapter.java look like below :
Next step, you have to extend the UserAdapter.java to RecyclerView.Adapter<UserAdapter.ViewHolder>. ViewHolder comes from inner class that view have created before.
Next, implement all method that required to be implemented. After you implement all method, the Adapter look like this :
That all, the first thing we do, to setup our RecyclerView Adapter. Now just add some attribute that relevant with our required.
Full code of UserAdapter.java :
After you finish with your Adapter, now time to modify your MainActivity.java. Do Like code below :
The output will show like below :