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

人走茶凉 提交于 2019-12-04 14:57:37

问题


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?


回答1:


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.




回答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;
}


来源:https://stackoverflow.com/questions/12858264/how-to-fix-android-view-viewgroup-jumpdrawablestocurrentstateviewgroup-java50

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!