12 июля, 2022

WeatherApp #10: RecyclerView Adapter – Part 2

WeatherAdapter.kt import android.view.LayoutInflaterimport android.view.Viewimport android.view.ViewGroupimport androidx.recyclerview.widget.DiffUtilimport androidx.recyclerview.widget.ListAdapterimport androidx.recyclerview.widget.RecyclerViewimport com.meter_alc_rgb.weatherappcursey.Rimport com.meter_alc_rgb.weatherappcursey.databinding.ListItemBindingclass WeatherAdapter : ListAdapter<WeatherModel, WeatherAdapter.Holder>(Comparator()) { class Holder(view: View) : RecyclerView.ViewHolder(view){ val binding = ListItemBinding.bind(view) fun bind(item: WeatherModel) = with(binding){ tvDate.text = item.time tvCondition.text = item.condition tvTemp.text = item.currentTemp } } class Comparator : DiffUtil.ItemCallback<WeatherModel>(){ override fun areItemsTheSame(oldItem: WeatherModel, newItem: WeatherModel): Boolean { return oldItem == newItem } override fun areContentsTheSame(oldItem: WeatherModel, newItem: WeatherModel): Boolean { return oldItem == newItem }… Подробнее »WeatherApp #10: RecyclerView Adapter – Part 2