如何在Alertdialog中添加听众论点的解雇
我正在采用一种创建自定义AlertDialog的方法,可以在其中调用此方法传递的文本,并在任何地方打开对话框。
我的问题是,当我使用它时,我需要在自定义视图的每个按钮中拨出一个解散,但是当我调用此方法时,系统无需了解对话框的任何信息。
因此,我需要对通过的听众或类似的东西添加“解雇”。
private fun showCustomAlertDialog(context: Context, title: String?, message: String?, positiveButtonClickListener: View.OnClickListener?, negativeButtonClickListener: View.OnClickListener?, neutralButtonClickListener: View.OnClickListener?, positiveText: String?, negativeText: String?, neutralText: String?){
val layoutInflater: LayoutInflater = layoutInflater
val alertLayout: View = layoutInflater.inflate(R.layout.layout_dialog, null)
val tvDialogTitle: TextView = alertLayout.findViewById(R.id.tv_dialog_title)
val tvDialogDescription: TextView = alertLayout.findViewById(R.id.tv_dialog_description)
val btnAccept: Button = alertLayout.findViewById(R.id.btn_dialog_accept)
val btnCancel: Button = alertLayout.findViewById(R.id.btn_dialog_cancel)
val btnNeutral: Button = alertLayout.findViewById(R.id.btn_dialog_neutral)
val alertDialog = AlertDialog.Builder(context)
alertDialog.setCancelable(false)
alertDialog.setView(alertLayout)
val dialog = alertDialog.create()
if (title != null) {
if(title.isNotEmpty()){
tvDialogTitle.text = title
}
}else{
tvDialogTitle.text = ""
}
if (message != null) {
if(message.isNotEmpty()){
tvDialogDescription.text = message
}
}else{
tvDialogDescription.text = ""
}
if(neutralButtonClickListener != null && (positiveButtonClickListener == null && negativeButtonClickListener == null)){
btnAccept.visibility = View.GONE
btnCancel.visibility = View.GONE
btnNeutral.visibility = View.VISIBLE
btnNeutral.setOnClickListener(neutralButtonClickListener)
if (neutralText != null) {
if(neutralText.isNotEmpty()){
btnNeutral.text = neutralText
}
}
}
if(neutralButtonClickListener == null && (positiveButtonClickListener != null && negativeButtonClickListener != null)) {
btnAccept.visibility = View.VISIBLE
btnCancel.visibility = View.VISIBLE
btnNeutral.visibility = View.GONE
btnAccept.setOnClickListener(positiveButtonClickListener)
btnCancel.setOnClickListener(negativeButtonClickListener)
if (positiveText != null) {
if(positiveText.isNotEmpty()){
btnAccept.text = positiveText
}
}
if (negativeText != null) {
if(negativeText.isNotEmpty()){
btnCancel.text = negativeText
}
}
}
dialog.show()
}
目前,我不知道如何在进行我的听众之后如何添加解雇。例如:
btnAccept.setOnClickListener(positiveButtonClickListener)
有建议吗?
谢谢
I'm doing a method to create a custom AlertDialog in which I can call this method passing text, and listener to open a dialog in everywhere.
My problem is that when I'm use it, I need to call a dismiss in every button of the custom view, but when I call this method the system no need to know anything about the dialog.
So, I need to add a "dismiss" on the passed listener or something like that.
private fun showCustomAlertDialog(context: Context, title: String?, message: String?, positiveButtonClickListener: View.OnClickListener?, negativeButtonClickListener: View.OnClickListener?, neutralButtonClickListener: View.OnClickListener?, positiveText: String?, negativeText: String?, neutralText: String?){
val layoutInflater: LayoutInflater = layoutInflater
val alertLayout: View = layoutInflater.inflate(R.layout.layout_dialog, null)
val tvDialogTitle: TextView = alertLayout.findViewById(R.id.tv_dialog_title)
val tvDialogDescription: TextView = alertLayout.findViewById(R.id.tv_dialog_description)
val btnAccept: Button = alertLayout.findViewById(R.id.btn_dialog_accept)
val btnCancel: Button = alertLayout.findViewById(R.id.btn_dialog_cancel)
val btnNeutral: Button = alertLayout.findViewById(R.id.btn_dialog_neutral)
val alertDialog = AlertDialog.Builder(context)
alertDialog.setCancelable(false)
alertDialog.setView(alertLayout)
val dialog = alertDialog.create()
if (title != null) {
if(title.isNotEmpty()){
tvDialogTitle.text = title
}
}else{
tvDialogTitle.text = ""
}
if (message != null) {
if(message.isNotEmpty()){
tvDialogDescription.text = message
}
}else{
tvDialogDescription.text = ""
}
if(neutralButtonClickListener != null && (positiveButtonClickListener == null && negativeButtonClickListener == null)){
btnAccept.visibility = View.GONE
btnCancel.visibility = View.GONE
btnNeutral.visibility = View.VISIBLE
btnNeutral.setOnClickListener(neutralButtonClickListener)
if (neutralText != null) {
if(neutralText.isNotEmpty()){
btnNeutral.text = neutralText
}
}
}
if(neutralButtonClickListener == null && (positiveButtonClickListener != null && negativeButtonClickListener != null)) {
btnAccept.visibility = View.VISIBLE
btnCancel.visibility = View.VISIBLE
btnNeutral.visibility = View.GONE
btnAccept.setOnClickListener(positiveButtonClickListener)
btnCancel.setOnClickListener(negativeButtonClickListener)
if (positiveText != null) {
if(positiveText.isNotEmpty()){
btnAccept.text = positiveText
}
}
if (negativeText != null) {
if(negativeText.isNotEmpty()){
btnCancel.text = negativeText
}
}
}
dialog.show()
}
At this moment I don't know how to add a dismiss after doing the listener that I passed. For example:
btnAccept.setOnClickListener(positiveButtonClickListener)
Any advice?
Thank you
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
用法:
Usage: