我的 findViewById 不工作。在我的片段中

My findViewById is not working. in my fragment

我的 findViewById 不工作。它不 link...

////我的fragment.contacts.xml

*<?xml version="1.0" encoding="utf-8"?>
<LinearLayout 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:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical"
    tools:context=".MainActivity">

    <EditText
        android:id="@+id/txtShowOnMap"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_marginStart="8dp"
        android:layout_marginTop="8dp"
        android:layout_marginEnd="8dp"
        android:contentDescription="@string/locationonmap"
        android:importantForAutofill="no"
        android:inputType="text"
        android:labelFor="@id/btnShowOnMap"
        android:minHeight="48dp"
        android:text="@string/store_location" />

    <Button
        android:id="@+id/btnShowOnMap"
        android:layout_width="395dp"
        android:layout_height="wrap_content"
        android:layout_marginStart="8dp"
        android:layout_marginEnd="8dp"
        android:text="@string/map" />

    </LinearLayout>*

////fragmentcontacts.xml

结束

我的contactsfragment.kt

请成功view.findViewById 对于片段,您需要添加根视图。