Advertisement
muhamad_lukman

adapterPager

Apr 25th, 2022
887
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Kotlin 1.03 KB | None | 0 0
  1. class OnBoardingAdapter(val context : Context, val onBoardingItem: List<OnBoardingItem>) : PagerAdapter(){
  2.  
  3.     override fun instantiateItem(container: ViewGroup, position: Int): Any {
  4.         val inflater = context.getSystemService(Context.LAYOUT_INFLATER_SERVICE) as LayoutInflater
  5.         val layoutScreen: View = inflater.inflate(R.layout.item_onboarding, null)
  6.         val img = layoutScreen.findViewById<ImageView>(R.id.img_on_boarding)
  7.         val desc = layoutScreen.findViewById<TextView>(R.id.tv_desc_on_boarding)
  8.  
  9.         img.setImageResource(onBoardingItem[position].image!!)
  10.         desc.text = onBoardingItem[position].description
  11.         container.addView(layoutScreen)
  12.         return layoutScreen
  13.     }
  14.     override fun getCount(): Int {
  15.        return onBoardingItem.size
  16.     }
  17.     override fun isViewFromObject(view: View, o: Any): Boolean {
  18.         return view === o
  19.     }
  20.  
  21.     override fun destroyItem(container: ViewGroup, position: Int, `object`: Any) {
  22.         container.removeView(`object` as View)
  23.     }
  24. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement