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
Android Kotlin RecyclerView возвращает только 1 элемент ⇐ Android
Форум для тех, кто программирует под Android
-
Anonymous
1714832780
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)
})
}
}
Подробнее здесь: [url]https://stackoverflow.com/questions/78419881/android-kotlin-recyclerview-return-only-1-item[/url]
Ответить
1 сообщение
• Страница 1 из 1
Перейти
- Кемерово-IT
- ↳ Javascript
- ↳ C#
- ↳ JAVA
- ↳ Elasticsearch aggregation
- ↳ Python
- ↳ Php
- ↳ Android
- ↳ Html
- ↳ Jquery
- ↳ C++
- ↳ IOS
- ↳ CSS
- ↳ Excel
- ↳ Linux
- ↳ Apache
- ↳ MySql
- Детский мир
- Для души
- ↳ Музыкальные инструменты даром
- ↳ Печатная продукция даром
- Внешняя красота и здоровье
- ↳ Одежда и обувь для взрослых даром
- ↳ Товары для здоровья
- ↳ Физкультура и спорт
- Техника - даром!
- ↳ Автомобилистам
- ↳ Компьютерная техника
- ↳ Плиты: газовые и электрические
- ↳ Холодильники
- ↳ Стиральные машины
- ↳ Телевизоры
- ↳ Телефоны, смартфоны, плашеты
- ↳ Швейные машинки
- ↳ Прочая электроника и техника
- ↳ Фототехника
- Ремонт и интерьер
- ↳ Стройматериалы, инструмент
- ↳ Мебель и предметы интерьера даром
- ↳ Cантехника
- Другие темы
- ↳ Разное даром
- ↳ Давай меняться!
- ↳ Отдам\возьму за копеечку
- ↳ Работа и подработка в Кемерове
- ↳ Давай с тобой поговорим...
Мобильная версия