Last active
March 21, 2018 01:53
-
-
Save CDRussell/69e6127ea47880906ded186f9510a9b2 to your computer and use it in GitHub Desktop.
This file contains 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
class TaskListAdapter(private val clickListener: (Task) -> Unit) : | |
ListAdapter<Task, ViewHolder>(TaskDiffCallback()) { | |
override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): ViewHolder { | |
val inflater = LayoutInflater.from(parent.context) | |
return ViewHolder(inflater.inflate(R.layout.item_task_row, parent, false)) | |
} | |
override fun onBindViewHolder(holder: ViewHolder, position: Int) { | |
holder.bind(getItem(position), clickListener) | |
} | |
class ViewHolder(itemView: View) : RecyclerView.ViewHolder(itemView) { | |
fun bind(task: Task, clickListener: (Task) -> Unit) { | |
itemView.taskTitle.text = task.title | |
itemView.setOnClickListener { clickListener(task) } | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment