Created
October 16, 2020 09:53
-
-
Save Tamkien/e5ca28a8a33fb8dfdfd99e067f3c9441 to your computer and use it in GitHub Desktop.
To create a simple dialog for each items of a recycleView.
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
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