Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

java.lang.IllegalStateException: The specified child already has a parent. #14

Closed
marekdef opened this issue Dec 30, 2019 · 1 comment
Closed
Labels
bug Something isn't working

Comments

@marekdef
Copy link

I want to use view.createSkeleton().showSkeleton() but if I do that I got exception

Caused by: java.lang.IllegalStateException: The specified child already has a parent. You must call removeView() on the child's parent first.
        at android.view.ViewGroup.addViewInner(ViewGroup.java:3936)
        at android.view.ViewGroup.addView(ViewGroup.java:3786)
        at android.view.ViewGroup.addView(ViewGroup.java:3727)
        at android.view.ViewGroup.addView(ViewGroup.java:3700)
        at com.faltenreich.skeletonlayout.SkeletonLayout.<init>(SkeletonLayout.kt:84)
        at com.faltenreich.skeletonlayout.SkeletonLayout.<init>(SkeletonLayout.kt:33)
        at com.faltenreich.skeletonlayout.SkeletonLayoutUtils.createSkeleton(SkeletonExtensions.kt:31)
        at com.faltenreich.skeletonlayout.SkeletonLayoutUtils.createSkeleton$default(SkeletonExtensions.kt:30)
        at pl.senordeveloper.skeletonview.MainActivity.onCreate(MainActivity.kt:14)

My layout is a textView inside ContraintLayout/FrameLayout and I am creating a skeleton in onCreate method (but this also fails if I do postDelayed or in onResume).

I can create a skeleton successfully if I wrap mentioned textview inside xml with SkeletonLayout so I guess I can expect createSkeleton to work in similar fashion (create a wrapper around existing view).

The question is: am I misusing this utility function?

@Faltenreich
Copy link
Owner

Thank you for reporting this problem!

There is indeed a problem when injecting a SkeletonLayout programmatically into a layout. As you have correctly assumed, the Skeleton serves as a wrapper around the original Views. So in the case of an injected View, we have to replace the original (to be masked) View with a SkeletonLayout which then contains the original View with all of its children.

I am currently working on a bugfix and expect a solution in version 2.0.1 later this day. Thanks again and have a nice day!

@Faltenreich Faltenreich added the bug Something isn't working label Jan 4, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants