mikepenz/FastAdapter

How can I judge the item is the last one in AbstractBindingItem

gudao20080 opened this issue · 1 comments

I want to do something in the last item, how to find which is the last item? please!!!

class PreviewPhotoItem(val item: Uri) : AbstractBindingItem<PhotoPreviewThumbItemBinding>() {
    override val type: Int
        get() = 0

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

    override fun bindView(
        holder: BindingViewHolder<PhotoPreviewThumbItemBinding>,
        payloads: List<Any>
    ) {
        super.bindView(holder, payloads)
        if (holder.layoutPosition == 0) {
            holder.itemView.apply {
                val lp = this.layoutParams as ViewGroup.MarginLayoutParams
                lp.leftMargin = context.resources.getDimensionPixelSize(
                    R.dimen.dp_16
                )

                this.layoutParams = lp
            }
        }
        
        // if is the last item, 

    }

    override fun bindView(binding: PhotoPreviewThumbItemBinding, payloads: List<Any>) {
        binding.ivPreviewThumb.setImageURI(item)
        binding.ivPreviewThumb?.alpha = if (isSelected) 1f else 0.5f
    }

}

@gudao20080 this is unrelated to the FastAdapter library. It's should not be the responsibility of the item to act on its position. Items are re-used, which is a core functionality of the RecyclerView.

If you want a footer, consider using a different item at the end, or use another adapter second adapter as footer.

See samples like this in the sample app.

Otherwise please consolidate Google's RV documentation for RV related matters.