简体   繁体   中英

Update glide sliderview visible items when sort a recycler view

I have an activity with a recycler view.

In my adapter, each item has some informations and a slider view thanks to Glide Slider ( https://github.com/firdausmaulan/GlideSlider ).

When I sort the list, all items are updated with the right informations, but the images remain in the same place for the first two items visible on the screen. When I scroll the page, the photos match the right items.

How to update the images of the visible items?

My function bind is working (the right informations are sent):

fun bind(property: Property) {
        val pictures = getPictures(property)

        if (mImageSlider == null) {
            GlideApp
                .with(context!!)
                .load(pictures[0])
                .centerCrop()
                .into(mPropertyView!!)
        }
        else {
            val requestOptions = RequestOptions().centerCrop()
            val arrayProperty = pictures.toTypedArray()

            for (i in 0 until pictures.size) {
                val sliderView = DefaultSliderView(context)

                // initialize SliderLayout
                sliderView
                    .image(pictures[i])
                    .setRequestOption(requestOptions)
                    .setProgressBarVisible(true)
                    .setOnSliderClickListener(this)

                sliderView.bundle(Bundle())

                sliderView.bundle.putString("advertId", property.advertId)
                sliderView.bundle.putStringArray("urlImg", arrayProperty)

                mImageSlider!!.addSlider(sliderView)
            }

            mImageSlider!!.stopAutoCycle()
            mImageSlider!!.addOnPageChangeListener(this)
        }

        ...
        viewAdapter.notifyDataSetChanged()
}

The function onSliderClick retrieves the wrong information for visible items:

override fun onSliderClick(slider: BaseSliderView?) {
        val intent = Intent(itemView.context, PropertyActivity::class.java)

        intent.putExtra("bundle", slider!!.bundle)

        itemView.context.startActivity(intent)
    }

The function onBindViewHolder gets the good informations.

I am not sure if I understand you right. But here is a previous answer https://stackoverflow.com/a/43586743/11136689 , which worked for me to get the old information out of my recycled view. So when onBind comes there is not the recycled information inside.

Hope this helps. Happy coding.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM