java AlertDialog。建设者setView导致堆栈溢出错误
我试图用自定义视图显示一个对话框,但我面对的是java.lang.StackOverflowError: stack size 8MB
,我不知道如何处理它。
这是我的密码。感谢您的帮助
对话框片段:
class MyDialogFragment : DialogFragment() {
override fun onCreateDialog(savedInstanceState: Bundle?): Dialog {
return activity?.let {
AlertDialog.Builder(it)
.setView(layoutInflater.inflate(R.layout.custom_dialog, null))
.create()
}
} ?: throw IllegalStateException("Activity cannot be null")
}
自定义对话框。xml:
<?xml version="1.0" encoding="utf-8"?>
<安卓.support.constraint.ConstraintLayout xmlns:安卓="http://schemas.安卓.com/apk/res/安卓"
xmlns:app="http://schemas.安卓.com/apk/res-auto"
安卓:layout_width="match_parent"
安卓:layout_height="match_parent">
<安卓.support.v7.widget.RecyclerView
安卓:id="@+id/recyclerView"
安卓:layout_width="0dp"
安卓:layout_height="0dp"
安卓:layout_marginStart="16dp"
安卓:layout_marginTop="16dp"
安卓:layout_marginEnd="16dp"
安卓:layout_marginBottom="16dp"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />
</安卓.support.constraint.ConstraintLayout>
共 (0) 个答案