Learn how to connect the model data displayed in the RecyclerView to the corresponding objects in the view layer.
This is a companion discussion topic for the original entry at https://www.raywenderlich.com/4568-beginning-recyclerview/lessons/4
Learn how to connect the model data displayed in the RecyclerView to the corresponding objects in the view layer.
I have a question.
the class Viewholder is as follow:
class ViewHolder(itemView: View?) : RecyclerView.ViewHolder(itemView) {
private fun bindView(creature: Creature) {
}
}
I just used autocomplete and it gave me the above class definition. with itemView with a "?.
I know what that means, that the itemView can be null.
My Question is
is it always better to handle such nullable possibilities like this
class ViewHolder(itemView: View?) : RecyclerView.ViewHolder(itemView) {
private fun bindView(creature: Creature) {
itemView.let {
it.creatureNameTextView.text = creature.fullName
it.creatureImageView.setImageResource(itemView.context.resources.getIdentifier(creature.uri, null, itemView.context.packageName))
}
}
}
using the let function?
Also I know that it is not necessary to have “?” in the constructor of ViewHolder but i just wanted to clear the unwrapping.
I hope this makes sense.
Thank you
@macsimus Can you please help with this when you get a chance? Thank you - much appreciated! :]