I want to make the move to View Binding in order the migrate to the 1.8.0 of the Gradle Plugin. I found a lot of posts but somehow I can't get it working for my Adapter:
class JustPlayedAdapter: RecyclerView.Adapter<JustPlayedViewHolder>() {
private var context: Context? = null
override fun getItemCount(): Int {
return lastPlayed.count()
}
override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): JustPlayedViewHolder {
val layoutInflater = LayoutInflater.from(parent.context)
val cellForRow = layoutInflater.inflate(R.layout.just_played_row, parent, false)
context = parent.context
return JustPlayedViewHolder(cellForRow)
}
override fun onBindViewHolder(holder: JustPlayedViewHolder, position: Int) {
holder.itemView.tijd.text = lastPlayed[position][0]
holder.itemView.artiest.text = lastPlayed[position][1]
holder.itemView.titel.text = lastPlayed[position][2]
holder.itemView.tijd.contentDescription = lastPlayed[position][0]
holder.itemView.artiest.contentDescription = lastPlayed[position][1]
holder.itemView.titel.contentDescription = lastPlayed[position][2]
holder.itemView.albumart.setImageBitmap(lastPlayedAlbumart[position])
if (lastPlayed[position][3] != "") {
//Apple music link beschikbaar
holder.itemView.isClickable = true
holder.itemView.appleMusicIcon.isVisible = true
holder.itemView.setOnClickListener {
println("stationAPP: appleMusicURL = " + lastPlayed[position][3])
//open Apple Music
val appleMusicURL = lastPlayed[position][3]
val intent = Intent(Intent.ACTION_VIEW, Uri.parse(appleMusicURL))
context!!.startActivity(intent)
}
} else {
//Apple music link NIET beschikbaar
holder.itemView.isClickable = false
holder.itemView.appleMusicIcon.isVisible = false
}
}
}
class JustPlayedViewHolder(view: View): RecyclerView.ViewHolder(view)
I manage to get it working for my Activities, but not for my 2 adapters.
I used the post: https://stackoverflow.com/a/60427658/833647 but that didn’t work for me. Who can help me out here?
See the answer which is different than the answers in that post.