Skip to content

Instantly share code, notes, and snippets.

@Tamkien
Created October 16, 2020 09:53
Show Gist options
  • Save Tamkien/e5ca28a8a33fb8dfdfd99e067f3c9441 to your computer and use it in GitHub Desktop.
Save Tamkien/e5ca28a8a33fb8dfdfd99e067f3c9441 to your computer and use it in GitHub Desktop.
To create a simple dialog for each items of a recycleView.
override fun onBindViewHolder(holder: RecyclerView.ViewHolder, position: Int) {
if (holder is EmployeeViewHolder) { //EmployeeViewHolder is my custom viewHolder to bind values
holder.bind(employees[position]) //employees is my list
holder.itemView.setOnClickListener {
val dialog = AlertDialog.Builder(it.context).create()
dialog.setTitle("Title")//your title here
dialog.setMessage("Message")//your message here
dialog.setButton(
AlertDialog.BUTTON_NEUTRAL, "OK" //a button labeled "OK"
) { _: DialogInterface, _: Int -> dialog.dismiss() }
dialog.show()
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment