How to fix 'android.view.ViewGroup.jumpDrawablesToCurrentState(ViewGroup.java:5035)' error in android
Asked Answered
T

2

48

I have layout with child (NOT as root) element RelativeLayout and then i create ViewPager and insert it as child of my Relative layout, so it's like

+Relative Layout (root)

|

+-- Relative Layout (child)

|

+-- -- ViewPager

For now moment - all ok.

But then i try add some view item to ViewPager with own layout then i got error

10-12 15:32:46.777: E/AndroidRuntime(6031): FATAL EXCEPTION: main
10-12 15:32:46.777: E/AndroidRuntime(6031): java.lang.StackOverflowError
10-12 15:32:46.777: E/AndroidRuntime(6031):     at android.view.ViewGroup.jumpDrawablesToCurrentState(ViewGroup.java:5035)

How do that ViewPager will me as Child of RelativeLayout with havin own Child Views?

Tetrode answered 12/10, 2012 at 11:39 Comment(0)
T
143

Problem solved!

It's happened because I call LayoutInflater.inflate([subViewOfViewPager], [ParentOfViewPager])

it should be:

LayoutInflater.inflate([subViewOfViewPager], [ParentOfViewPager], false))

More words:

It's happened because when called inflate with second parameter, view inserting as subchild of given ViewGroup, and then I try add this View to ViewPager. View can have only one Parent ViewGroup element. The third parameter sets attachToRoot to false to avoid this.

Tetrode answered 12/10, 2012 at 12:3 Comment(5)
Using LayoutInflater.inflate(resId, container, false) in a child fragment does the same trick for me.Gaffe
@anoniim: This is actually the correct way to inflate, inflate(id, null) should not be used since it will ignore all layout_... attributes on your layout's root element.Especial
Thanks, I did exactly what @anoniim recommended and worked.Calix
LayoutInflater.inflate([subViewOfViewPager],null) saved my life.. Now i can go home and sleep :DTestosterone
would have never found this discrepancy myselfLakshmi
F
2

Simplified version of answer

@Nullable
@Override
public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
    View view = inflater.inflate(R.layout.cab_listing, container,false);
    return view;
}
Fission answered 2/7, 2017 at 10:12 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.