我有一个用MVVM制作的android项目,在转换到不同的Page(带有findNavController的片段)并返回到带有RecyclerView的屏幕后,在RecyclerView移位位置的项目遇到了麻烦。我在网上搜索了此信息,但找不到任何解决方案。我看过类似以下内容的内容,但无法解决。我很想听听您的一些提示或示例代码!
RecyclerView Adapter change selected position in List Scrolling
val recyclerView: RecyclerView = binding.mainRecycleview
val adapter = HomeAdapter(context!!, viewModel)
recyclerView.adapter = adapter
val layoutManager = GridLayoutManager(activity, COLUMN_COUNT, RecyclerView.VERTICAL, false)
recyclerView.layoutManager = layoutManager
recyclerView.isMotionEventSplittingEnabled = false
setGridDecoration(recyclerView, adapter, layoutManager)
adapter.setOnItemClickListener(object : HomeListAdapter.OnItemClickListener {
override fun onClick(view: View, homedata: MainModel) = onClickItem(view, article)
})
。
class HomeAdapter(val context: Context, val viewModel: MainModel) : RecyclerView.Adapter<MainAdapter.ViewHolder>() {