ViewPager with two tabs causes IndexOutOfBoundsException when sliding and clicking

前端 未结 1 559
旧巷少年郎
旧巷少年郎 2020-12-12 06:05

I have two tabs in which I add two different lists of data, both tabs share a single recyclerview, so at my viewpager adapter, I just create a new instance to populate the d

相关标签:
1条回答
  • 2020-12-12 06:35
    viewPagerAdapter.productsList = productsList
    viewPagerAdapter.drinksList = drinksList
    viewPagerAdapter.notifyDataSetChanged()
    

    If i didn't understand wrong when you came here your viewPagerAdapter already created and you defined your lists as nonNull in adapter( MutableList< Product >).

    fun getItem(position: Int):Product{
        return productList[position]
    }
    

    For example this block tries to get position 1 when adapter is created and before you set data. It gonna return IndexOutOfBoundsException.

    Maybe you must try to move this lists in viewPagerAdapter's constructor.

    0 讨论(0)
提交回复
热议问题