Android:从父片段引用子片段

Android:从父片段引用子片段,android,android-fragments,android-nested-fragment,Android,Android Fragments,Android Nested Fragment,我有一个嵌套片段场景。尝试引用父片段中的子片段将给出空值。我错过了什么 这是父片段的布局文件 <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="match_parent" android:layout_height="wrap_content" android:orientation="vertical">

我有一个嵌套片段场景。尝试引用父片段中的子片段将给出空值。我错过了什么

这是父片段的布局文件

   <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:orientation="vertical">

    <!-- Statically nested fragment -->
    <fragment
        android:name="reports.fragments.fragments.usageBreakUp.fragments.Filter"
        android:id="@+id/fragment_filter"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"/>

</LinearLayout>
你试过这个吗

filter = (Filter) view.findViewById(R.id.fragment_filter);

您可能会在
populateStorageFilter
中获得NPE,因为您的子片段的
onViewCreated
尚未调用,即子视图尚未初始化。因此,如果您在
populateStorageFilter
中使用任何视图引用,它们都是
null
。您必须等待子片段的视图创建,然后调用
populateStorageFilter

filter = (Filter) view.findViewById(R.id.fragment_filter);