Skip to content

Commit

Permalink
ViewBinding in Adapter
Browse files Browse the repository at this point in the history
  • Loading branch information
arifaizin committed Nov 13, 2020
1 parent ab0f667 commit 6fa3042
Showing 1 changed file with 7 additions and 6 deletions.
Expand Up @@ -7,7 +7,7 @@ import androidx.recyclerview.widget.RecyclerView
import com.bumptech.glide.Glide
import com.dicoding.tourismapp.R
import com.dicoding.tourismapp.core.data.source.local.entity.TourismEntity
import kotlinx.android.synthetic.main.item_list_tourism.view.*
import com.dicoding.tourismapp.databinding.ItemListTourismBinding
import java.util.ArrayList

class TourismAdapter : RecyclerView.Adapter<TourismAdapter.ListViewHolder>() {
Expand All @@ -33,18 +33,19 @@ class TourismAdapter : RecyclerView.Adapter<TourismAdapter.ListViewHolder>() {
}

inner class ListViewHolder(itemView: View) : RecyclerView.ViewHolder(itemView) {
private val binding = ItemListTourismBinding.bind(itemView)
fun bind(data: TourismEntity) {
with(itemView) {
with(binding) {
Glide.with(itemView.context)
.load(data.image)
.into(iv_item_image)
tv_item_title.text = data.name
tv_item_subtitle.text = data.address
.into(ivItemImage)
tvItemTitle.text = data.name
tvItemSubtitle.text = data.address
}
}

init {
itemView.setOnClickListener {
binding.root.setOnClickListener {
onItemClick?.invoke(listData[adapterPosition])
}
}
Expand Down

0 comments on commit 6fa3042

Please sign in to comment.