在转换到其他屏幕并返回后,RecyclerView项目会更改位置

时间:2019-06-13 02:13:37

标签: android kotlin android-recyclerview

我有一个用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>() {

0 个答案:

没有答案