riku
2022-02-18 d59d55575d913646b7a90fca651904ab889c6723
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
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)
        }
    }
}