When adding view inside layout and when removing and re-adding, it throws like this.
The specified child already has a parent. You must call removeView() on the child's parent first
Any Idea???
linearLayout.addView(view);
This line is called often(ie. everytime when activity resumes), so i've added like:
((ViewGroup)view.getParent()).removeAllViewsInLayout();
linearLayout.removeView(view);
if(linearLayout.getChildCount()==0)
linearLayout.addView(view);
But again same probs!
如果您在活动中动态创建布局子级,并且如果返回则转到另一个活动,则必须删除视图并使用新信息重新创建它。
((ViewManager)view.getParent()).removeView(view);
这工作!!!
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.