0

It tells me there is a mismatch, it requires "AdapterView<*>! but it has found "Int". How do I fix this?

Error Screenshot

class InstructorViewHolder(itemView: View, listener: OnItemClickListener) : RecyclerView.ViewHolder(itemView){
    val firstName: TextView = itemView.findViewById(R.id.tvInstructorName)
    val phoneNumber: TextView = itemView.findViewById(R.id.tvInstructorNumber)
    val age: TextView = itemView.findViewById(R.id.tvInstructorAge)

    init {
        itemView.setOnClickListener {
            listener.onItemClick(absoluteAdapterPosition)
        }
    }

}

I tried to use "bindingAdapterPosition" but still got the same error. On this documentation it states that the return type should be Int, that why I am confused as to why it is asking me to provide "AdapterView<*>".

I looked at this link however, it doesn't exactly explain how to implement the feature.

dan1st
  • 12,568
  • 8
  • 34
  • 67

1 Answers1

0

You're calling listener.onItemClick, and from that very blurry screenshot it looks like listener is an AdapterView.OnItemClickListener. From the docs:

public abstract void onItemClick (AdapterView<?> parent, 
                View view, 
                int position, 
                long id)

So the problem isn't absoluteAdapterPosition - that's providing an Int just fine! But the error is complaining that you're passing an Int because what it's actually expecting is an AdapterView<*>. That's what it required, but what it found was the Int you're providing, right? So you can tell where the problem is coming from by the language it's using. (And since that method has a few other parameters, it'll complain about those being missing if you fix this one)

Going by what you're trying to do (call onItemClick with a single Int parameter) I'm guessing you imported the wrong OnItemClickListener - that's often what's happened if you try to use a thing and it looks completely wrong!

cactustictacs
  • 17,935
  • 2
  • 14
  • 25