Open microacup opened 10 years ago
错误描述:
07-27 17:27:50.453: E/AndroidRuntime(1528): java.lang.IllegalStateException: The specified child already has a parent. You must call removeView() on the child's parent first.
解决方案:
inflater.inflate方法第三个参数传false
@Override public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { View view = inflater.inflate(R.layout.user_summary, container, false); return view; }
问题原因:
inflater.inflate(R.layout.user_summary, container, false);
t.add(R.id.menu_frame, mFrag);
类似案例:
LinearLayout listMachines = (LinearLayout) findViewById(R.id.water_level_page_water_level_setting); LayoutInflater inflater = LayoutInflater.from(WaterLevelActivity.this); View tlWaterLevelInfo = inflater.inflate(R.layout.unit_time_water_level_item, null); listMachines.addView(tlWaterLevelInfo); listMachines.addView(tlWaterLevelInfo); //这个地方出错了。
错误描述:
解决方案:
inflater.inflate方法第三个参数传false
@Override public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { View view = inflater.inflate(R.layout.user_summary, container, false); return view; }
问题原因:
inflater.inflate(R.layout.user_summary, container, false);
第三个参数的意思是是否把当前view加入root中,也就是是自动初始化到界面。而程序中又有其他地方调用了t.add(R.id.menu_frame, mFrag);
手动添加了一遍,所以添加了两遍。类似案例: