android - How to change item position of a recycle view from within its adapter?
问题描述
Is it possible to change the item from within the adapter itself?
What am I trying to a achieve?
I have created a simple recycler view and it has a simple list item, but when the user clicks on the item a bottom sheet dialog gets displayed (that bottom sheet is being created in the adapter itself so it's different for every item) that bottom sheet dialog have a back and next button which can allow the user to move back and forth through the item view
When the user clicks on item -> bottom sheet dialog gets displayed -> if he presses next I have to show next following item with its bottom sheet opened.
How can I move from I item to another within the adapter?
解决方案
you can pass position and list item as ArrayList to bottom sheet and update UI on next and previous buttons.
for example, you can create a method in your bottom sheet to update bottom sheet UI:
var listItem = ArrayList<Objects>()
var position = 0
private fun updateUi() {
val item = listItem[position]
///update ui with item
}
on next button click:
position += 1
if (position == listItem.size)
{
// end of list
} else
{
updateUi()
}
and on pervious button click:
position -= 1
if (position == -1)
{
// end of list
} else
{
updateUi()
}
推荐阅读
- listview - 如何在 ViewModel 和 Xaml 的网格中使列和行可递增?
- vb.net - 如何找到一年中的当前周数,星期一是新一周的开始?
- reactjs - docker-compose,未能解决:rpc 错误:代码 = 未知 desc = 无法计算缓存键:“/app/package.json”未找到:未找到
- python - zipfile - 如何允许提取所有文件,即使是同名文件?
- flutter - 让 TextEditingController 在 null_safety 中为 null
- python - 在 Python 中的列表中合并数据框列表
- javascript - es6 整体导出导入或解构
- javascript - 使用自定义用户代理重定向网页
- c - 在 C 中,我如何知道字符串 char 是否具有特定值?
- webhooks - 气流上 Teams webhook 的连接设置出现一般错误