gpt4 book ai didi

java - ViewPager2#onpageselect StackOverflowError

转载 作者:行者123 更新时间:2023-12-01 18:08:55 27 4
gpt4 key购买 nike

我在回收 View 中使用 vp2

        override fun convert(helper: BaseViewHolder, item: Tweet) {
val medias = item.medium.split(",")
if (!item.video) {
helper.getView<View>(R.id.vp).show()
helper.getView<View>(R.id.insdotview).show()
helper.getView<View>(R.id.videoview).hide()
val ad = TweetPhotoAdapter()
val a = medias.toMutableList()
ad.setNewData(a)
val vp2= helper.getView<ViewPager2>(R.id.vp)
vp2.registerOnPageChangeCallback(object : ViewPager2.OnPageChangeCallback() {
override fun onPageSelected(position: Int) {
LogUtils.w(onPageSelected(position))
super.onPageSelected(position)
}
})

如果我在遇到convert()时添加vp2.registerOnPageChangeCallback,则会出现StackOverflowError错误就像这样

java.lang.StackOverflowError: stack size 8MB
at FFActivity$UserTweetAdapter2$convert$1.onPageSelected(FFActivity.kt:149)
at FFActivity$UserTweetAdapter2$convert$1.onPageSelected(FFActivity.kt:149)
at FFActivity$UserTweetAdapter2$convert$1.onPageSelected(FFActivi.kt:149)
at FFActivity$UserTweetAdapter2$convert$1.onPageSelected(FFActivity.kt:149)
at FFActivity$UserTweetAdapter2$convert$1.onPageSelected(FFActivity.kt:149)
at FFActivity$UserTweetAdapter2$convert$1.onPageSelected(FFActivity.kt:149)
at FFActivity$UserTweetAdapter2$convert$1.onPageSelected(FFActivity.kt:149)
at FFActivity$UserTweetAdapter2$convert$1.onPageSelected(FFActivity.kt:149)

如果我不添加 PageChangeCallback ,似乎没有问题

最佳答案

修改为

   override fun convert(helper: BaseViewHolder, item: Tweet) {
val medias = item.medium.split(",")
if (!item.video) {
helper.getView<View>(R.id.vp).show()
helper.getView<View>(R.id.insdotview).show()
helper.getView<View>(R.id.videoview).hide()
val ad = TweetPhotoAdapter()
val a = medias.toMutableList()
ad.setNewData(a)
val vp2= helper.getView<ViewPager2>(R.id.vp)
vp2.registerOnPageChangeCallback(object : ViewPager2.OnPageChangeCallback() {
override fun onPageSelected(position: Int) {
LogUtils.w(position) // this line
super.onPageSelected(position)
}
})

关于java - ViewPager2#onpageselect StackOverflowError,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/60503054/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com