I am creating an animated drawable and then adding it to a FrameLayout
. The variable is created as a class field and then, each new AnimatedDrawable
is created and added to the frame, like that :
for (int i = 0; i < 10; i++) {
sampleView = new SampleView(Drink.this);
frame.addView(sampleView);
}
But when I do that from the background thread (AsyncTask in which I run the frame.addView(sampleView);
in runOnUIThread to avoid issue of updating UI from another thread than UI's), I get an error unless I add this to my code : frame.removeView(sampleView);
So, I can't grab the issue here...More over, when I do that, instead of getting 10 elements, I only get 3...
The error I get is the classical :
java.lang.IllegalStateException: The specified child already has a parent. You must call removeView() on the child's parent first.