【发布时间】:2014-11-19 10:19:28
【问题描述】:
我有嵌套片段场景。尝试从父片段引用子片段会给出空值。我在这里错过了什么?
这是父片段的布局文件。
<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>
这是我尝试从父片段访问子片段的方式
@Override
public void onViewCreated(View view, @Nullable Bundle savedInstanceState) {
super.onViewCreated(view, savedInstanceState);
Log.i(LOG_TAG, "ON VIEW CREATED");
filter = (Filter) getChildFragmentManager().findFragmentById(R.id.fragment_filter);
filter.populateStorageFilter(); // NPE here
}
【问题讨论】:
标签: android android-fragments android-nested-fragment