Skip to content

Instantly share code, notes, and snippets.

@kingjinho
Last active November 30, 2022 11:31
Show Gist options
  • Save kingjinho/f1acfc36eb0dc5f2607631197267beb1 to your computer and use it in GitHub Desktop.
Save kingjinho/f1acfc36eb0dc5f2607631197267beb1 to your computer and use it in GitHub Desktop.
Contructor of FragmentContainerView
//생성자
internal constructor(
context: Context,
attrs: AttributeSet,
fm: FragmentManager
) : super(context, attrs) {
//생략된 부분에서 이름과 태그를 체크합니다.
...
if (name != null && existingFragment == null) {
if (id == View.NO_ID) {
val tagMessage = if (tag != null) " with tag $tag" else ""
throw IllegalStateException(
"FragmentContainerView must have an android:id to add Fragment $name$tagMessage"
)
}
//Fragment 생성
val containerFragment: Fragment =
fm.fragmentFactory.instantiate(context.classLoader, name)
//생성된 Fragment의 onInflate(...) 호출
containerFragment.onInflate(context, attrs, null)
fm.beginTransaction()
.setReorderingAllowed(true)
.add(this, containerFragment, tag)
.commitNowAllowingStateLoss()
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment