마스터Q&A 안드로이드는 안드로이드 개발자들의 질문과 답변을 위한 지식 커뮤니티 사이트입니다. 안드로이드펍에서 운영하고 있습니다. [사용법, 운영진]

Flagment 의 onCreateView 에서 container 이 null 이나오는 이유가 뭐가있을까요?

0 추천

Flagment 의 onCreateView  에서 container 이 null 이나오는 이유가 뭐가있을까요?

xml 에서 프래그먼트를 포함시키고 디버깅해보면

onCreateView  에서 container 이 null 이나와서 죽습니다

이경우 어디를 살펴봐야될까요?

 

<androidx.coordinatorlayout.widget.CoordinatorLayout
    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"
    tools:ignore="RtlHardcoded"
    >

    <fragment
        android:name="wri.www.net.web.WebViewFragment"
        android:id="@+id/fragment1"
        android:layout_weight="1"
        android:layout_width="fill_parent"
        android:layout_height="0dip"
        />
</androidx.coordinatorlayout.widget.CoordinatorLayout>

 

@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
                   Bundle savedInstanceState) {
   if (container == null) {  //여기로 들어옵니다
      // We have different layouts, and in one of them this
      // fragment's containing frame doesn't exist.  The fragment
      // may still be created from its saved state, but there is
      // no reason to try to create its view hierarchy because it
      // won't be displayed.  Note this is not needed -- we could
      // just run the code below, where we would create and return
      // the view hierarchy; it would just never be used.
      return null;
   }

   mCtx = getActivity();

   init();
   View v = init();

   return v;
}

 

잡부 (5,090 포인트) 님이 2020년 4월 11일 질문

답변 달기

· 글에 소스 코드 보기 좋게 넣는 법
· 질문에 대해 추가적인 질문이나 의견이 있으면 답변이 아니라 댓글로 달아주시기 바랍니다.
표시할 이름 (옵션):
개인정보: 당신의 이메일은 이 알림을 보내는데만 사용됩니다.
스팸 차단 검사:
스팸 검사를 다시 받지 않으려면 로그인하거나 혹은 가입 하세요.
...