Android Kotlin RecyclerView возвращает только 1 элементAndroid

Форум для тех, кто программирует под Android
Ответить
Anonymous
 Android Kotlin RecyclerView возвращает только 1 элемент

Сообщение Anonymous »

android kotlin recyclerview возвращает только 1 элемент.
и текстовое представление отображается в одном элементе.
введите здесь описание изображения
class HttpAdapter(context: Context) :
ListAdapter(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() {
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
}
}
}

Я продолжил модифицировать onBindViewHolder().
Однако данные продолжают распределяться по 1 элементу.
и коду MainActivity
р>
class MainActivity : AppCompatActivity() {

private val binding: ActivityMainBinding by lazy { ActivityMainBinding.inflate(layoutInflater) }
private val httpList = ArrayList()
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContentView(binding.root)

val adapter = HttpAdapter(this)
binding.recyclerView.layoutManager = LinearLayoutManager(this, LinearLayoutManager.VERTICAL, false)
binding.recyclerView.adapter = adapter

val viewModel = ViewModelProvider(this)[HttpViewModel::class.java]
viewModel.getData()

viewModel.result.observe(this, Observer {
adapter.submitList(it)
})
}
}


Подробнее здесь: https://stackoverflow.com/questions/784 ... nly-1-item
Ответить

Быстрый ответ

Изменение регистра текста: 
Смайлики
:) :( :oops: :roll: :wink: :muza: :clever: :sorry: :angel: :read: *x)
Ещё смайлики…
   
К этому ответу прикреплено по крайней мере одно вложение.

Если вы не хотите добавлять вложения, оставьте поля пустыми.

Максимально разрешённый размер вложения: 15 МБ.

Вернуться в «Android»