zhpanvip / BannerViewPager

🚀 An awesome banner view for Android,Based on ViewPager2. 这可能是全网最好用的ViewPager轮播图。简单、高效,一行代码实现循环轮播,一屏三页任意变,指示器样式任你挑。
Apache License 2.0
3.62k stars 440 forks source link

Kotlin setAdapter to Nothing #107

Closed youmu178 closed 4 years ago

youmu178 commented 4 years ago

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'

zhpanvip commented 4 years ago

检查一下是不是泛型写的有问题,demo中用kotlin是可以正常运行的。

youmu178 commented 4 years ago

检查一下是不是泛型写的有问题,demo中用kotlin是可以正常运行的。

viewPager.setAdapter得时候就提示 adapter to Nothing

zhpanvip commented 4 years ago

可以贴下代码吗,demo是可以正常运行的。

zhpanvip commented 4 years ago

用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)
    }
zhpanvip commented 4 years ago

issue先关掉了,如果仍然有问题可以reopen issue.