• Register
+1 vote
68 views

Problem :

When I call a blank layout and afterwards call my layout it gives me the following error:
the specified child already has a parent. you must call removeview() on the child's parent first.
by (6.9k points)  

1 Answer

0 votes

Solution :

In my case it comes when i want to add view by parent to other view

View root = inflater.inflate(R.layout.single, null);
LinearLayout lyt = root.findViewById(R.id.lytRoot);
lytAll.addView(lyt);  //it crashes

So to avoid the crash one must add parent view like this

View root = inflater.inflate(R.layout.single, null);
LinearLayout lyt = root.findViewById(R.id.lytRoot);
lytAll.addView(root); //it works fine
I followed above steps and my issue got resolved.

Further Readings :

by (36.1k points)  
...