안드로이드 개발 질문/답변
(글 수 45,052)
/* 해당경우에는 Fragment 가 정상적으로 출력 됩니다.*/ FragmentTransaction ft = fragmentManager.beginTransaction(); if ( currentFragment != null ) { ft.remove(currentFragment); } makeFragment(cls); ft.add(fragmentId, currentFragment); ft.commit();
하지만 이 경우에는 java.lang.IllegalStateException: The specified child already has a parent. You must call removeView() on the child's parent first. 를 뱉어냅니다.
FragmentTransaction ft = fragmentManager.beginTransaction(); navigationStack.pop(); ft.remove(currentFragment); // ft.commit(); // ft = fragmentManager.beginTransaction(); Fragment prev = navigationStack.peek().fragment; ft.add(fragmentId, prev); ft.commit();
Stack을 이용해서 다중적인 Tab관리를 위해서 만들었는데 잘 안되네요 ㅠㅠ
이부분 해결할 방법 없을까요??
벌써 서른이라니..
해당 에러 메시지는 view가 아직 어떤 parent 하에 있는데 다른 곳에 add시킬 때 발생합니다.
prev fragment 를 add하기 전에 다른 곳에 속해 있는 것은 아닌지 확인해보셔야 할 것 같습니다.