Android-Image-Slider icon indicating copy to clipboard operation
Android-Image-Slider copied to clipboard

Kotlin: Unresolved reference: SliderItem

Open primeviltom opened this issue 5 years ago • 2 comments

Hi there,

I would like to use this in a project that I am writing in Kotlin, so I am in the process of converting the example code to Kotlin..

However, I've run into trouble where my SliderViewAdapter class is not aware of the SliderItem class from the library (I'm assuming). I get the error: Unresolved reference: SliderItem.

My SliderViewAdapterExample.kt class looks like:

//various imports
import com.smarteist.autoimageslider.SliderViewAdapter
class SliderViewAdapterExample(context: Context) : SliderViewAdapter<SliderAdapterViewHolder>(){

    private val context = context
    private var mSliderItems: List<SliderItem> = ArrayList()

//    fun renewItems(sliderItems: List<SliderItem?>?) {
//        mSliderItems = sliderItems!!
//        notifyDataSetChanged()
//    }
//
//    fun deleteItem(position: Int) {
//        mSliderItems.removeAt(position)
//        notifyDataSetChanged()
//    }
//
//    fun addItem(sliderItem: SliderItem?) {
//        mSliderItems.add(sliderItem)
//        notifyDataSetChanged()
//    }

    fun onCreateViewHolder(parent: ViewGroup?, viewType: Int): SliderAdapterViewHolder {
        val layoutInflater = LayoutInflater.from(parent?.context)

        val imageSliderView = layoutInflater.inflate(R.layout.image_slider, parent, false)

        return SliderAdapterViewHolder(imageSliderView)
    }

    override fun onBindViewHolder(viewHolder: SliderAdapterViewHolder?, position: Int) {
        TODO("Not yet implemented")
    }

    override fun getCount(): Int {
        TODO("Not yet implemented")
    }
}

class SliderAdapterViewHolder(val view: View) : SliderViewAdapter.ViewHolder(view) {
//    var itemView: View? = null
    var imageViewBackground: ImageView? = null
    var imageGifContainer: ImageView? = null
    var textViewDescription: TextView? = null

    fun SliderAdapterVH(itemView: View) {
        super.itemView
        imageViewBackground = view.findViewById(R.id.iv_auto_image_slider) //was itemView
        imageGifContainer = view.findViewById(R.id.iv_gif_container)
        textViewDescription = view.findViewById(R.id.tv_auto_image_slider)
//        this.itemView = itemView
    }
}

I am a reasonably new Android developer, so it's likely that I am missing something obvious! Any help would be appreciated, especially if anyone has implemented this fantastic library in a Kotlin project!

primeviltom avatar Aug 27 '20 02:08 primeviltom

I have the same issue. Were you able to resolve?

Grandolf49 avatar Sep 13 '20 10:09 Grandolf49

Look at the code and you will find a class named SliderItem. Copy it to your project and you should be good. The developer forgot to add it to the readme file

rabiefizazi avatar Oct 28 '20 02:10 rabiefizazi