Last active
November 13, 2020 13:04
-
-
Save thalespupo/2946579b5b1176408ee08ea3f4f6ccfd to your computer and use it in GitHub Desktop.
MyAdapter KotlinSynthetic
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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