Skip to content

Error while trying to set up custom scroll #48

@ibrajix

Description

@ibrajix

This is what I want:
On click of any alphabet, it should jump to the item in the list instead of scrolling (Default behaviour)

I have implemented custom scrolling like this as per the doc.

` binding.rcvAllArtistes.adapter = allArtisteAdapter
    binding.rcvAllArtistes.layoutManager = LinearLayoutManager(context)
    binding.fastscroller.setupWithRecyclerView(
        binding.rcvAllArtistes,
        { position ->
            val item = allArtisteAdapter.artistes[position] // Get your model object
            // or fetch the section at [position] from your database
            FastScrollItemIndicator.Text(
                item.artisteName?.substring(0, 1)!!.toUpperCase(Locale.ROOT) // Grab the first letter and capitalize it
            ) // Return a text indicator
        }
    )
    binding.fastscroller.useDefaultScroller = false

val smoothScroller: LinearSmoothScroller = object : LinearSmoothScroller(context) {
        override fun getVerticalSnapPreference(): Int = SNAP_TO_START
    }

val linearLayoutManager = LinearLayoutManager(context)

binding.fastscroller.itemIndicatorSelectedCallbacks  += object : FastScrollerView.ItemIndicatorSelectedCallback {
        override fun onItemIndicatorSelected(
            indicator: FastScrollItemIndicator,
            indicatorCenterY: Int,
            itemPosition: Int
        ) {
            binding.rcvAllArtistes.stopScroll()
            smoothScroller.targetPosition = itemPosition
            linearLayoutManager.startSmoothScroll(smoothScroller)
        }
    }

    binding.fastscrollerThumb.setupWithFastScroller(binding.fastscroller) `

When I click on the scrollbar, I get ERROR:

java.lang.NullPointerException: Attempt to read from field 'androidx.recyclerview.widget.RecyclerView$ViewFlinger androidx.recyclerview.widget.RecyclerView.mViewFlinger' on a null object reference

Also, how to change the size of the alphabets shown in scrollbar. No textSize attribute.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions