OnClick listener not working
CodeArtisanRiz opened this issue · comments
H M Rizwan Mazumder commented
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
H M Rizwan Mazumder commented
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()