The first one represents the class that will be managed by the list, and the second one is the viewHolder. If you pay attention, you will notice the ListAdapter class has two type parameters. This method returns an object of the same type as the one we used as the first type parameter of the UserAdapter class in our case it’s User. With the ListAdapter, we retrieve the data at a given position by calling the getItem(position) method. In this layout, we declared a variable of type user, that’s why in the onBindViewHolder method I can have access to the user property of the binding of our viewHolder that we initialize by the value returned by the getItem(position) method.Īt the moment, we declare a variable in XML it doesn’t have a value yet, that’s why we had to initialize the user declarer property in the item_user.xml file in the onBindViewHolder method. It was generated from the layout item_user.xml. I think it tells you something about the ItemUserBinding class. The UserAdapter class contains an internal class which takes a binding property of type ItemUserBinding, and which inherits from the RecylerView.ViewHolder class. As you can see I didn’t use a classic adapter, I used the ListAdapter that came with Jetpack, but it will also work with a classic adapter,
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |