mikepenz / FastAdapter

The bullet proof, fast and easy to use adapter library, which minimizes developing time to a fraction...
https://mikepenz.dev
Apache License 2.0
3.84k stars 494 forks source link

viewBinding issue #960

Closed azizi436 closed 3 years ago

azizi436 commented 3 years ago

Hi 1) Im using viewBinding in my project and now i want to use it for FastAdapter but i dont know what should i put in <> 2)What is the type and why we should use type exactly?

image

*my xml item class name is job_item and its Viewbinding is JobItemBinding

mikepenz commented 3 years ago
class GalleryItem(...) : AbstractBindingItem<GalleryItemBinding>() {

    override val type: Int
        get() = R.id.gallery_item

    override fun bindView(binding: GalleryItemBinding, payloads: List<Any>) {
        super.bindView(binding, payloads)
        ...
    }

    override fun createBinding(inflater: LayoutInflater, parent: ViewGroup?): GalleryItemBinding {
        return GalleryItemBinding.inflate(inflater, parent, false)
    }
}

A sample could look like

azizi436 commented 3 years ago
class GalleryItem(...) : AbstractBindingItem<GalleryItemBinding>() {

    override val type: Int
        get() = R.id.gallery_item

    override fun bindView(binding: GalleryItemBinding, payloads: List<Any>) {
        super.bindView(binding, payloads)
        ...
    }

    override fun createBinding(inflater: LayoutInflater, parent: ViewGroup?): GalleryItemBinding {
        return GalleryItemBinding.inflate(inflater, parent, false)
    }
}

A sample could look like

Ok thanks, but how can i use position ( i mean item position ) in bindView ?

mikepenz commented 3 years ago

That's not supported with this item. you can look at the base abstract code: https://github.com/mikepenz/FastAdapter/blob/develop/library-extensions-binding/src/main/java/com/mikepenz/fastadapter/binding/AbstractBindingItem.kt#L18

and adjust it so you get the adapterPosition of the ViewHolder