AlertDialog.Builder.setView导致StackOverflowError

时间:2019-01-03 17:50:25

标签: java android kotlin dialog stack-overflow

我试图显示一个带有自定义视图的对话框,但是我面对着java.lang.StackOverflowError: stack size 8MB,但我不知道如何处理它。 这是我的代码。任何帮助表示赞赏。

DialogFragment:

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")
}

custom_dialog.xml:

<?xml version="1.0" encoding="utf-8"?>
<android.support.constraint.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    android:layout_width="match_parent"
    android:layout_height="match_parent">

    <android.support.v7.widget.RecyclerView
        android:id="@+id/recyclerView"
        android:layout_width="0dp"
        android:layout_height="0dp"
        android:layout_marginStart="16dp"
        android:layout_marginTop="16dp"
        android:layout_marginEnd="16dp"
        android:layout_marginBottom="16dp"
        app:layout_constraintBottom_toBottomOf="parent"
        app:layout_constraintEnd_toEndOf="parent"
        app:layout_constraintStart_toStartOf="parent"
        app:layout_constraintTop_toTopOf="parent" />
</android.support.constraint.ConstraintLayout>

0 个答案:

没有答案