【发布时间】:2021-03-18 05:53:31
【问题描述】:
我已经阅读了几个类似的问题,但我无法回答任何问题。症结在于
val popupMenu = findViewById<RecyclerView>(R.id.popmenu)
总是返回 null。
这里是activity_popup.xml
<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/popupactivity"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".PopupActivity">
<androidx.recyclerview.widget.RecyclerView
android:id="@+id/popmenu"
android:layout_width="match_parent"
android:layout_height="match_parent"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />
</androidx.constraintlayout.widget.ConstraintLayout>
这里是设置 PopupWindow 的代码:
val inflater = getSystemService(Context.LAYOUT_INFLATER_SERVICE) as LayoutInflater
val popupView = inflater.inflate(R.layout.activity_popup, null)
popupWin = PopupWindow(popupView, popupWidth, popupHeight, true)
val layoutMgr = LinearLayoutManager(applicationContext)
val popupMenu = findViewById<RecyclerView>(R.id.popmenu)
我做错了什么?
【问题讨论】:
-
这能回答你的问题吗? findviewbyid returns null in a dialog
标签: android android-recyclerview popupwindow