Kotlin 从AlertDialog“自身”获取数据
我目前正试图打开一个AlertDialog,其中会显示一些数据Kotlin 从AlertDialog“自身”获取数据,kotlin,dialog,fragment,Kotlin,Dialog,Fragment,我目前正试图打开一个AlertDialog,其中会显示一些数据 class AlertsDialogRemi : Fragment() { override fun onCreateView(inflater: LayoutInflater, container: ViewGroup?, savedInstanceState: Bundle?): View? { return inflater.inflate(R.layout.alerts_dialog, container
class AlertsDialogRemi : Fragment() {
override fun onCreateView(inflater: LayoutInflater, container: ViewGroup?, savedInstanceState: Bundle?): View? {
return inflater.inflate(R.layout.alerts_dialog, container, false)
}
override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
super.onViewCreated(view, savedInstanceState)
val alerts = arrayOf("AlertsDialogRemi 1", "AlertsDialogRemi 2", "AlertsDialogRemi 3")
for(alert in alerts){
Log.i(TAG, "Alert : $alert")
}}
我从这个主要活动中称之为:
fun showDialog(){
mydialog = Dialog(this, R.style.DialogCustomTheme)
mydialog.requestWindowFeature(Window.FEATURE_NO_TITLE)
mydialog.setContentView(R.layout.alerts_dialog_remi)
mydialog.create()
txt = mydialog.findViewById(R.id.close_modal_alerte)
txt.isEnabled = true
txt.setOnClickListener{
mydialog.cancel()
}
mydialog.show()
}
当我将片段作为真实片段打开时,我可以查看我的警报。但当我以对话框的形式打开它时,我看不到警报,但我显示了布局
借助showDialog,如何在AlertDialog中以对话框的形式获取警报?此对话框与AlertsDialogRemi类无关。 在mydialog.show之前声明对话框的setOnShowListener,并将对话框显示在lambda中时要执行的代码放入:
mydialog.setOnShowListener {
//write your code here
}
SETONSHOWLISTER
public void setOnShareListenerDialogInterface.OnShareListener侦听器
设置显示对话框时调用的侦听器
要获取对话框,可以使用DialogFragment而不是Fragment。请参阅详细信息。如果你想要相同的布局,我应该使用一个充气器并放置内容。我确实使用了setOnShowListener,但我没有使用我的Alert类。我已经直接在setOnShowListener中填充了该对话框。谢谢