android kotlin recyclerview return only 1 item.
and A textview is displayed within one item.
enter image description here
class HttpAdapter(context: Context) :
ListAdapter<RentBikeStatus, HttpAdapter.VH>(HttpDiffCallback()) {
inner class VH(binding: RecyclerItemBinding) : RecyclerView.ViewHolder(binding.root) {
val title: TextView = binding.tv
}
override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): VH {
val binding = RecyclerItemBinding.inflate(LayoutInflater.from(parent.context),parent,false)
return VH(binding)
}
override fun onBindViewHolder(holder: VH, position: Int) {
val item = getItem(position)
Log.d("dddddd",item.toString())
Log.d("dddddd",item.rentBikeStatus.row[position].stationName)
val stationNames = item.rentBikeStatus.row.map { it.stationName }.joinToString("n")
holder.title.text = stationNames
}
private class HttpDiffCallback : DiffUtil.ItemCallback<RentBikeStatus>() {
override fun areItemsTheSame(oldItem: RentBikeStatus, newItem: RentBikeStatus): Boolean {
return oldItem.rentBikeStatus.row.getOrNull(1)?.stationName == newItem.rentBikeStatus.row.getOrNull(
1
)?.stationName
}
override fun areContentsTheSame(oldItem: RentBikeStatus, newItem: RentBikeStatus): Boolean {
return oldItem.rentBikeStatus.row.getOrNull(1)?.stationName == newItem.rentBikeStatus.row.getOrNull(
1
)?.stationName
}
}
}
I continued to modify onBindViewHolder().
However, data continues to be distributed to 1 item.
New contributor
athena kof99 is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.