I am unable to attach the views from my xml file in onBindViewHolder of Recycler View in my Adapter. I'm getting the following error:
Unresolved reference: ivArticleImage
I am using DiffUtil Class.
I Can access them by Binding method but by normal i can't. SomeBody Plss help!! here is my XML file
<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:padding="4dp"
android:layout_margin="4dp">
<ImageView
android:id="@+id/ivArticleImage"
android:layout_width="160dp"
android:layout_height="90dp"
android:scaleType="centerCrop"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />
</androidx.constraintlayout.widget.ConstraintLayout>
My adapter class
class MyAdapter : RecyclerView.Adapter<MyAdapter.ArticleViewHolder>() {
inner class ArticleViewHolder(itemView: View) : RecyclerView.ViewHolder(itemView)
private val differCallback = object : DiffUtil.ItemCallback<Article>() {
override fun areItemsTheSame(oldItem: Article, newItem: Article): Boolean {
return oldItem.url == newItem.url
}
override fun areContentsTheSame(oldItem: Article, newItem: Article): Boolean {
return oldItem == newItem
}
}
private val differ = AsyncListDiffer(this, differCallback)
override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): ArticleViewHolder {
return ArticleViewHolder(
LayoutInflater.from(parent.context).inflate(R.layout.item_article, parent, false)
)
// item_artcile is my XMl file
}
override fun onBindViewHolder(holder: ArticleViewHolder, position: Int) {
val article = differ.currentList[position]
holder.itemView.apply {
Glide.with(this).load(article.urlToImage).into(ivArticleImage)// giving error
}
}
override fun getItemCount(): Int {
return differ.currentList.size
}
}
'Article' is My data class..
I tried various method but error was still there only solution which i was able to find was to use binding method. but I am not using viewBinding in my project.