i have the following kotlin class which is for a recyclerview storing images. when i try…
Jump to turn (8)
- 1i have the following kotlin class which is for a recyclerview storing images. wh
- 2i have copied my code to a new activity, which does the same, but has a differen
- 3actually its because of my database constructor. how can i add a secondary const
- 4i also copied the view xml, and made sure to change element ids. however, the vi
- 5actually this happens with the other view as well, but only if the recycler is e
- 6the recycler is set to a fixed width and height, but in some it initially has no
- 7i just realized it appears broken even if there is an image. this is a problem
- 8give me an xml view boilerplate
- User
i have the following kotlin class which is for a recyclerview storing images. when i try to delete an image using a context menu, it crashes with an exception that r.id.recycler cannot be null. what could be the cause? class MyViewHolder(itemView: View, private val listener: MyAdapter.OnImageClickListener?) : RecyclerView.ViewHolder(itemView) { val imageView: ImageView = itemView.findViewById(R.id.image_view)
codeinit { imageView.setOnLongClickListener { val popupMenu = PopupMenu(itemView.context, itemView) popupMenu.inflate(R.menu.deleteimage) popupMenu.setOnMenuItemClickListener { menuItem -> return@setOnMenuItemClickListener when (menuItem.itemId) { R.id.delete -> { // call a listener method to delete the image at this position listener?.onDeleteImage(adapterPosition, itemView.findViewById(R.id.recycler)) true } else -> false } } popupMenu.show() true } }