martinapinky / staggered-grid

Android RecyclerView with Staggered Grid Layout Manager

Home Page:https://medium.com/swlh/staggered-recyclerview-with-multiple-selection-in-kotlin-8eb37d5ba9e1

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

OnClick listener not working

CodeArtisanRiz opened this issue · comments

hello, I am trying to add onClick action for items but doing so crashes the app.

tried on PostsAdapter
'''
override fun onBindViewHolder(holder: ListViewHolder, position: Int) {
holder.setPostImage(postItems[position])

    holder.postImageView.setOnClickListener { view ->
        Toast.makeText(view.context, position, Toast.LENGTH_SHORT).show()

    }
}

'''
help me with the solution.
Thanks

Fixed there was an error from my side:
It should be
Toast.makeText(context.applicationContext, position, Toast.LENGTH_SHORT).show()
instead of
Toast.makeText(view.context, position, Toast.LENGTH_SHORT).show()