Skip to content

Instantly share code, notes, and snippets.

@thalespupo
Last active November 13, 2020 13:04
Show Gist options
  • Save thalespupo/2946579b5b1176408ee08ea3f4f6ccfd to your computer and use it in GitHub Desktop.
Save thalespupo/2946579b5b1176408ee08ea3f4f6ccfd to your computer and use it in GitHub Desktop.
MyAdapter KotlinSynthetic
import kotlinx.android.synthetic.main.list_item_example.view.*
class MyAdapter : ListAdapter<String, MyAdapter.MyViewHolder>(DiffCallBack()) {
override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): MyViewHolder {
val view =
LayoutInflater.from(parent.context)
.inflate(R.layout.list_item_example, parent, false)
return MyViewHolder(view)
}
override fun onBindViewHolder(holder: MyViewHolder, position: Int) {
holder.bind(getItem(position).orEmpty())
}
class MyViewHolder(itemView: View) : RecyclerView.ViewHolder(itemView) {
fun bind(item: String) {
// Uso do Kotlin Synthetic
itemView.myTextView?.text = item
}
}
class DiffCallBack : DiffUtil.ItemCallback<String>() {
override fun areItemsTheSame(oldItem: String, newItem: String) = false
override fun areContentsTheSame(oldItem: String, newItem: String) = false
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment