View 带对话框的布局充气机

View 带对话框的布局充气机,view,kotlin,layout-inflater,View,Kotlin,Layout Inflater,我试图扩大我的自定义布局(一个对话框片段) 我的函数showDialog()中有这个 val inflatedView=layoutInflater.inflate(R.layout.alerts\u dialog\u remi,null) mydialog=Dialog(这个,R.style.DialogCustomTheme) mydialog.requestWindowFeature(窗口.功能\u无\u标题) mydialog.setContentView(R.layout.alerts

我试图扩大我的自定义布局(一个对话框片段)

我的函数showDialog()中有这个

val inflatedView=layoutInflater.inflate(R.layout.alerts\u dialog\u remi,null)
mydialog=Dialog(这个,R.style.DialogCustomTheme)
mydialog.requestWindowFeature(窗口.功能\u无\u标题)
mydialog.setContentView(R.layout.alerts\u dialog\u remi)
mydialog.setOnShowListener{
val text=充气视图.findViewById(R.id.alerte_标题)
val lp=LinearLayout.LayoutParams(LinearLayout.LayoutParams.WRAP_内容,LinearLayout.LayoutParams.WRAP_内容)
text.setText(“text”)}
mydialog.create()
txt=mydialog.findViewById(R.id.close\u modal\u Alert)
txt.isEnabled=true
txt.setOnClickListener{
mydialog.cancel()
}
mydialog.show()
}

但是我在对话框片段中没有看到“文本”字符串。我尝试将膨胀视图放入setOnShowListener中,但它也没有任何作用。

您不需要膨胀视图,因为
对话框。setContentView
正是为您这样做的

您需要的是从lambda内部获得充气视图

像这样:

 mydialog.setOnShowListener {
    val text = it.view.findViewById<TextView>(R.id.alerte_title)
mydialog.setonswowlistener{
val text=it.view.findviewbyd(R.id.alerte_title)

在本例中,视图从何而来?如果我将其替换,则会起作用。使用mydialog查看。谢谢
 mydialog.setOnShowListener {
    val text = it.view.findViewById<TextView>(R.id.alerte_title)