Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Error replacing two fragments with scrollviews

I have 2 fragments and both have Scrollviews in them, I make a selection from a ListView and that replaces the first fragment with the other fragment that has the scrollview.

The problem is that when I try to replace the fragment with the new one I get an error saying ScrollView can only contain one direct child which it does, it has one RelativeLayout which holds all the content.

If i take the ScrollView out of the first fragments view I do not get the error and the fragment gets replaced fine but I need the scrollview in the first fragment.

What is causing this issue, does replacing a fragment not remove the view fully?

StackTrace:

11-01 18:45:00.895: E/AndroidRuntime(3833): FATAL EXCEPTION: main
11-01 18:45:00.895: E/AndroidRuntime(3833): java.lang.IllegalStateException: ScrollView can host only one direct child
11-01 18:45:00.895: E/AndroidRuntime(3833):     at android.widget.ScrollView.addView(ScrollView.java:229)
11-01 18:45:00.895: E/AndroidRuntime(3833):     at android.app.FragmentManagerImpl.moveToState(FragmentManager.java:840)
11-01 18:45:00.895: E/AndroidRuntime(3833):     at android.app.FragmentManagerImpl.moveToState(FragmentManager.java:1035)
11-01 18:45:00.895: E/AndroidRuntime(3833):     at android.app.BackStackRecord.run(BackStackRecord.java:635)
11-01 18:45:00.895: E/AndroidRuntime(3833):     at android.app.FragmentManagerImpl.execPendingActions(FragmentManager.java:1397)
11-01 18:45:00.895: E/AndroidRuntime(3833):     at android.app.FragmentManagerImpl$1.run(FragmentManager.java:426)
11-01 18:45:00.895: E/AndroidRuntime(3833):     at android.os.Handler.handleCallback(Handler.java:615)
11-01 18:45:00.895: E/AndroidRuntime(3833):     at android.os.Handler.dispatchMessage(Handler.java:92)
11-01 18:45:00.895: E/AndroidRuntime(3833):     at android.os.Looper.loop(Looper.java:137)
11-01 18:45:00.895: E/AndroidRuntime(3833):     at android.app.ActivityThread.main(ActivityThread.java:4745)
11-01 18:45:00.895: E/AndroidRuntime(3833):     at java.lang.reflect.Method.invokeNative(Native Method)
11-01 18:45:00.895: E/AndroidRuntime(3833):     at java.lang.reflect.Method.invoke(Method.java:511)
11-01 18:45:00.895: E/AndroidRuntime(3833):     at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:786)
11-01 18:45:00.895: E/AndroidRuntime(3833):     at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:553)
11-01 18:45:00.895: E/AndroidRuntime(3833):     at dalvik.system.NativeStart.main(Native Method)

this is how I replace the fragment

ft.replace(R.id.frameTwo, individual);
ft.addToBackStack(null).commit();
like image 603
tyczj Avatar asked Jun 22 '26 01:06

tyczj


1 Answers

found the problem apparently you cant have a scrollview as you base view, I wrapped it in a RelativeLayout and it works now

like image 105
tyczj Avatar answered Jun 23 '26 18:06

tyczj



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!