0

What is the use of the function isViewFromObject in this case :

internal class ImageSliderAdapter(
    private val context: Context,
    private val imageModelArrayList: ArrayList<String>
) :
    PagerAdapter() {

    override fun getCount(): Int {
        return imageModelArrayList.size
    }

    override fun isViewFromObject(view: View, viewObject: Any): Boolean {
        return view === viewObject
    }

    override fun instantiateItem(container: ViewGroup, position: Int): Any {
        val inflater = context.getSystemService(Context.LAYOUT_INFLATER_SERVICE) as LayoutInflater
        val view = inflater.inflate(R.layout.layout_item_slider, container, false)

        val imageModelUrl = imageModelArrayList[position]


        Glide.with(context)
            .load(imageModelUrl)
            .placeholder(R.drawable.ic_placeholder_category)
            .diskCacheStrategy(DiskCacheStrategy.ALL)
            .fallback(R.drawable.ic_placeholder_category)
            .error(R.drawable.ic_placeholder_category)
            .into(view.imageViewViewPager)



        view.imageViewViewPager.setOnClickListener {
            val intent = Intent(context, ImageSlidingActivity::class.java)
//            intent.putStringArrayListExtra(PARCELABLE_OBJECT, imageModelArrayList)
            intent.putStringArrayListExtra(PARCELABLE_OBJECT, imageModelArrayList)
            intent.putExtra(ITEM_POSITION, position)
            context.startActivity(intent)
        }

        val viewPager = container as ViewPager
        viewPager.addView(view, 0)

        return view
    }

    override fun destroyItem(container: ViewGroup, position: Int, viewObject: Any) {
        val viewPager = container as ViewPager
        val view = viewObject as View
        viewPager.removeView(view)
    }
}

This image slider adapter is used to view different images on performing vertical slides on the screen, my question is what is the use of the isViewFromObject() function in this code.

  • This image slider adapter is used to view different images on performing vertical slides on the screen, my question is what is the use of the isViewFromObject() function in this code. Yes it does – aditya hulsure Jun 12 '20 at 11:21
  • Please do select that question as having solved your problem then, so that we all know that this post is resolved. Thanks! – Mike M. Jun 12 '20 at 11:23

0 Answers0