问题描述
我一直试图将库设置为视图,所以我创建了一个扩展PagerAdapter的类,就像在链接中一样。 I followed this
但是我的问题是我无法将setAdapter设置为viewPager,因为它要求输入RecycleView.Adapter
Val iAdapter=PagerAdapter(this,galleryUri) //creating object
viewPager.adapter=iAdapter // type mismatched here
但是在链接上的代码上没有这样的问题,每个人都这样做。我做错了吗?
PageAdapter.kt
class PageAdapter(context: Context,arrayList: ArrayList<Uri>) : PagerAdapter() {
private var mContext: Context? =null
private var galleryUri= arraylistof<Uri>()
private var layoutInflater: LayoutInflater? =null
init {
this.mContext=context
this.galleryUri=arrayList
this.layoutInflater=context.getSystemService(Context.LAYOUT_INFLATER_SERVICE) as LayoutInflater
}
override fun isViewFromObject(view: View,`object`: Any): Boolean {
return view==`object` as LinearLayout
}
override fun getCount(): Int {
return galleryUri.size
}
override fun instantiateItem(container: ViewGroup,position: Int): Any {
val itemView=(layoutInflater?.inflate(R.layout.image_container,container,true))
val imageView= itemView?.findViewById<ImageView>(R.id.imageContainer)
imageView?.setimageURI(galleryUri[position])
container.addView(itemView)
return itemView as Any
}
override fun destroyItem(container: ViewGroup,position: Int,`object`: Any) {
container.removeView(`object` as LinearLayout)
}
}
谢谢!
解决方法
暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!
如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。
小编邮箱:dio#foxmail.com (将#修改为@)