سؤال

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!

هل كانت مفيدة؟

المحلول 2

((ViewManager)view.getParent()).removeView(view);

This Worked!!!

نصائح أخرى

if you create childs of layout in activity dynamically and you go to another activity if you return you must remove views and recreate it with new informations.

مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top