igalata / Bubble-Picker

An easy-to-use animation which can be used for content picking for Android
https://medium.com/@igalata13/how-to-create-a-bubble-selection-animation-on-android-627044da4854#.js8nebsx6
1.4k stars 248 forks source link

Add custom data to PickerItem #62

Closed LionZXY closed 6 years ago

LionZXY commented 6 years ago

Add customData for get in onClickListener() any data. Like id, url and any other information that we insert into the adapter.

For example:

class GenreAdapter(var list: List<Genre>) : BubblePickerAdapter {
    override val totalCount: Int
        get() = list.size

    override fun getItem(position: Int): PickerItem {
        val item = PickerItem()
        val genre = list[position]
        item.title = genre.name
        item.customData = genre.id
        return item
    }
}

Result:

picker.listener = object : BubblePickerListener {
            override fun onBubbleDeselected(item: PickerItem) {
                if (item.customData != null && item.customData is Int) {
                    // Using id
                }
            }

            override fun onBubbleSelected(item: PickerItem) {
                TODO("not implemented") //To change body of created functions use File | Settings | File Templates.
            }

        }