Depois de editar os dados do usuário com o AlertDialog, preciso de um refresh na recyclerView pra atualizar o que foi editado
o AlertDialog esta atualizando diretamente no SQLite
Estou com dificuldade de utilizar o método notifyDataSetChanged()
alguém pode me dar uma sugestão faz favor?
class ListAdapter(
private var userList: List<User>
) : RecyclerView.Adapter<ListAdapter.AdapterViewHolder>() {
lateinit var dataBaseSQLite: DataBaseSQLite
private lateinit var dialog: AlertDialog
override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): AdapterViewHolder {
val itemView = LayoutInflater.from(parent.context).inflate(R.layout.item_usuario, parent, false)
return AdapterViewHolder(itemView)
}
override fun onBindViewHolder(holder: AdapterViewHolder, position: Int) {
holder.textName.text = userList[position].name
holder.textEdit.setOnClickListener { view ->
editUser(view, position)
}
}
override fun getItemCount() = userList.size
class AdapterViewHolder(itemView: View) : RecyclerView.ViewHolder(itemView) {
val textName = itemView.findViewById<TextView>(R.id.text_item_name)
val textEdit = itemView.findViewById<TextView>(R.id.text_item_editar)
}
fun editUser(view: View, position: Int) {
val build = AlertDialog.Builder(view.context, R.style.ThemeCustomDialog)
val dialogBinding = DialogAlertEditBinding
.inflate(LayoutInflater.from(view.context))
dialogBinding.buttonDialogEdit.setOnClickListener {
dataBaseSQLite = DataBaseSQLite(it.context)
dataBaseSQLite.updateUser(
User(
id = userList[position].id,
name = dialogBinding.editDialogName.text.toString(),
email = dialogBinding.editDialogEmail.text.toString(),
password = dialogBinding.editDialogSenha.text.toString(),
)
)
***AQUI*** .notifyDataSetChanged()
dialog.dismiss()
}
build.setView(dialogBinding.root)
dialog = build.create()
dialog.show()
}