Unresolved reference: textView

I’m trying to create a recyclerView, but when I try to reference my textView I get an error that says Unresolved Reference: textViewTitle, I have tried many ways and I could not, I appreciate your wise help.

class RecyclerAdapter(private val userList: ArrayList<Sitios> = ArrayList()) :
    RecyclerView.Adapter<RecyclerAdapter.ViewHolder>() {

    inner class ViewHolder(itemView: View) : RecyclerView.ViewHolder(itemView)

    override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): ViewHolder {
        val v = LayoutInflater.from(parent.context).inflate(R.layout.card_view, parent, false)

        return ViewHolder(v)

    override fun onBindViewHolder(holder: ViewHolder, position: Int) {

        //Unresolved reference: textViewTitle
        holder.itemView.textViewTitle.text = userList[position].description

    override fun getItemCount(): Int = userList.size

replace with holder.itemView.findViewById<TextView>(R.id.textViewTitle).text = ...
or use something like Data Binding or View Binding

1 Like

I can see this inner class which you are referencing, however, it does not contain any reference to your TextView object.

Probably you want to create something like:

inner class ViewHolder(itemView: View) : RecyclerView.ViewHolder(itemView) {
        var textViewTitle = itemView.findViewById<TextView>(R.id.textViewTitle)

This way you will have a reference to that textViewTitle which you’re looking for (in your onBindViewHolder method).

Let me know if that helps. :slight_smile:

1 Like