0

I have an android project made with MVVM and having trouble with the items in the RecyclerView shift position after transition to different Page(Fragment with findNavController) and coming back to the Screen with the RecyclerView. I searched about it online but cannot find any solutions. I've seen something like the following but cannot fix it. I would love to hear some tips or sample code from you!
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>() {
Nancy
  • 129
  • 2
  • 13

0 Answers0