package cn.flightfeather.thirdappmodule.view
|
|
import android.support.v4.view.PagerAdapter
|
import android.view.View
|
import android.view.ViewGroup
|
|
/**
|
* @author riku
|
* Date: 2020/6/22
|
*/
|
class ViewPagerAdapter(private val dataList: List<View>, private val titleList: List<String> = emptyList()) : PagerAdapter() {
|
override fun isViewFromObject(p0: View, p1: Any): Boolean {
|
return p0 == p1
|
}
|
|
override fun getCount(): Int {
|
return dataList.size
|
}
|
|
override fun instantiateItem(container: ViewGroup, position: Int): Any {
|
container.addView(dataList[position % dataList.size])
|
return dataList[position % dataList.size]
|
}
|
|
override fun destroyItem(container: ViewGroup, position: Int, `object`: Any) {
|
container.removeView(dataList[position % dataList.size])
|
}
|
|
override fun getPageTitle(position: Int): CharSequence? {
|
if (position < titleList.size) {
|
return titleList[position]
|
} else {
|
return super.getPageTitle(position)
|
}
|
}
|
}
|