Closed youmu178 closed 4 years ago
检查一下是不是泛型写的有问题,demo中用kotlin是可以正常运行的。
检查一下是不是泛型写的有问题,demo中用kotlin是可以正常运行的。
viewPager.setAdapter得时候就提示 adapter to Nothing
可以贴下代码吗,demo是可以正常运行的。
用kotlin 必须把BannerViewPager声明成员变量,并设置泛型,然后通过findViewById获取。
private lateinit var mViewPager: BannerViewPager<CustomBean, CustomPageViewHolder>
private fun setupViewPager() {
mViewPager = findViewById(R.id.viewpager)
mViewPager.apply {
setCanLoop(false)
setPageTransformer(PageTransformerFactory.createPageTransformer(Random().nextInt(6)))
setIndicatorMargin(0, 0, 0, resources.getDimension(R.dimen.dp_100).toInt())
setIndicatorSliderGap(resources.getDimension(R.dimen.dp_10).toInt())
setIndicatorSlideMode(IndicatorSlideMode.SMOOTH)
setIndicatorSliderRadius(resources.getDimension(R.dimen.dp_3).toInt(), resources.getDimension(R.dimen.dp_4_5).toInt())
registerOnPageChangeCallback(object : ViewPager2.OnPageChangeCallback() {
override fun onPageSelected(position: Int) {
BannerUtils.log("position:$position")
updateUI(position)
}
})
adapter = WelcomeAdapter().apply {
mOnSubViewClickListener = CustomPageViewHolder.OnSubViewClickListener { _, position -> ToastUtils.show("Logo Clicked,position:$position") }
}
setIndicatorSliderColor(ContextCompat.getColor(this@WelcomeActivity, R.color.white),
ContextCompat.getColor(this@WelcomeActivity, R.color.white_alpha_75))
}.create(data)
}
issue先关掉了,如果仍然有问题可以reopen issue.
Out-projected type 'BannerViewPager<out Any!, out (BaseViewHolder<Any!>..BaseViewHolder<*>?)>!' prohibits the use of 'public open fun setAdapter(p0: BaseBannerAdapter<T!, VH!>!): BannerViewPager<T!, VH!>! defined in com.zhpan.bannerview.BannerViewPager'