android开发的同学对fragment都不陌生 当然今天记录一个嵌套使用中的问题看错误如下
java.lang.IllegalArgumentException: Binary XML file line #93: Duplicate id 0x7f10046e, tag null, or parent id 0xffffffff with another fragment for com.XXX.fragment.XXXXFragment
解决方法
覆写fragmentA的onDestroyView方法,当fragmentA销毁的时候,手动销毁fragmentB。这个是stackoverflow提到的解决办法
https://stackoverflow.com/questions/27589590/error-inflating-class-fragment-duplicate-id-tag-null-or-parent-id-with-anoth
@Override
public void onDestroyView() {
super.onDestroyView();
Fragment fragment = mActivity.getSupportFragmentManager().findFragmentById(R.id.fragment);
if(fragment != null){
mActivity.getSupportFragmentManager().beginTransaction().remove(fragment ).commit();
}
网友评论