what is listadapter in android
ListAdapter is a wrapper around the AyncListDiffer helper. It includes computing diffs between Lists on a background thread and handling updates at different adapter positions. All you need to do is make a call to the submitList(data: List<T>) function and it will compute the best way to update the items for you.
What is ListAdapter?
ListAdapter is just an extension of RecyclerView. Adapter . Its computes diffs between Lists on a background thread with AsyncListDiff . You can obviously create a RecyclerView. Adapter to work in same way
example of list adapter:
class UserAdapter : ListAdapter<User, UserAdapter.UserViewHolder>(UserComparator) {
override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): UserViewHolder {
val view = LayoutInflater
.from(parent.context)
.inflate(R.layout.item_user, parent, false)
return UserViewHolder(view)
}
override fun onBindViewHolder(holder: UserViewHolder, position: Int) {
val user = getItem(position)
holder.bind(user)
}
class UserViewHolder(itemView: View) : RecyclerView.ViewHolder(itemView) {
private val tvName = itemView.tvName
fun bind(user: User) {
tvName.text = user.name
}
}
}
No comments:
Post a Comment