I got this:
class RecentAdapter(private val context: Context, private val videolist: MutableList<Videos>) : RecyclerView.Adapter<RecentAdapter.ViewHolder>(){
override fun onBindViewHolder(holder: RecyclerView.ViewHolder, position: Int) {
val video = videolist[position]
holder.title.text = video.title
holder.remove.setOnClickListener {
videolist.removeAt(holder.adapterPosition)
notifyItemRemoved(holder.adapterPosition)
}
}
override fun getItemCount() = videolist.size
override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): ViewHolder {
val view = LayoutInflater.from(parent.context).inflate(R.layout.videoview, parent, false)
return ViewHolder(view)
}
class ViewHolder(itemView: View?) : RecyclerView.ViewHolder(itemView!!){
val title = itemView!!.videoviewTitle!!
val remove = itemView!!.videoviewRemove!!
val like = itemView!!.videoviewLike!!
}
}
I get the error:
Class 'RecentAdapter' is not abstract and does not implement abstract base class member public abstract fun onBindViewHolder(@NonNull p0: RecentAdapter.ViewHolder, p1: Int): Unit defined in android.support.v7.widget.RecyclerView.Adapter
on class RecentAdapter
And
'onBindViewHolder' overrides nothing
And
Unresolved reference on title
and remove
Can someone help me?
Change onBindViewHolder()
's signature to this:
override fun onBindViewHolder(holder: ViewHolder, position: Int)
The 1st argument's type is ViewHolder
and not RecyclerView.ViewHolder
For the first question:
You are not overriding the right method. In your constructor, you are declaring that the ViewHolder
to use is RecentAdapter.ViewHolder
, but your onBindViewHolder
references the generic RecyclerView.ViewHolder
. To fix this, simply change
override fun onBindViewHolder(holder: RecyclerView.ViewHolder, position: Int) {
to
override fun onBindViewHolder(holder: RecentAdapter.ViewHolder, position: Int) {
For the second question, I am not sure what the error is with the given files. Make sure you that there are views with Ids videoViewTitle
and videoViewRemove
within the videoview
layout file to start?
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.