Skip to content Skip to sidebar Skip to footer

Viewgroup.java Addviewinner Issue

i keep getting following errors, it's basically same error but keeps occuring on different lines Fatal Exception: java.lang.IllegalStateException: The specified child already ha

Solution 1:

Try double checking how you are inflating the view.

There are two possible ways:

  1. Passing the parent to the inflater:

    LayoutInflater.from(context).inflate(R.layout.layout, this, true);
    
  2. Keep the view without the parent:

    LayoutInflater.from(context).inflate(R.layout.layout, null);
    

When using the first method, you cannot call addView() with the view as parameter. Using the second way, the view is not pinned to parent, therefore you can invoke addView()

Post a Comment for "Viewgroup.java Addviewinner Issue"