0

Dont know whether there's an issue with my code or the recyclerview itself, but whenever I'm trying to populate a new list to the recyclerview, it auto scrolls itself to the top of the index. This does not happen when I set the items' width to MATCH PARENT, only if I am setting a custom width to the itemviews, this strange bug happens.I also tried using notifyItemRangeChanged or notifyItemChanged, but unfortunately nothing seems to work.

val layoutManager = LinearLayoutManager(context, LinearLayoutManager.HORIZONTAL, false)
recyclerViewSubscriptions.layoutManager = layoutManager
recyclerViewSubscriptions.adapter = subscriptionAdapter
subscriptionAdapter?.setData(subscriptionList, true, null, false)

Adapter setData code:

fun setData(
    users: MutableList<SubscribtionListItem>?,
    hideButtons: Boolean,
    activeSubscriptionType: Int?,
    isPendingRequest: Boolean,
    isPlanReplaced: Boolean = false,
    standardPlanDuration: Int = 0
) {
    this.subscribtionListItem = users
    notifyDataSetChanged()
}
Shikhar
  • 644
  • 1
  • 10
  • 20
  • https://stackoverflow.com/q/56465852/11880323 don't create an adapter everytime – cmak Jun 06 '23 at 13:56
  • @cmak Iam not creating a new adapter each time,,,I'm just updating the data..I also tried notifyItemChanged but still this peculiar issue persists. Also as mentioned if I remove the custom width and set the itemview's parent width to MATCH_PARENT then this issues does not occur – Shikhar Jun 07 '23 at 04:54
  • Try updating the existing list instead of setting new one – cmak Jun 07 '23 at 16:26
  • @cmak tried the same..also played around with notifyItemRangeChange and notifyItemIndex..still the issue persists – Shikhar Jun 08 '23 at 05:28
  • What about overriding `getItemId`? – cmak Jun 08 '23 at 06:50
  • @cmak yes and issue is still the same. Also, Im reiterating that if I remove the custom width and set the itemview's parent width to MATCH_PARENT then this issues does not occur...hence this should not be a concern of item id I suppose – Shikhar Jun 08 '23 at 08:15

0 Answers0