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)

*xml that holds the fragments*

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android";
    android:layout_width="match_parent"
    android:layout_height="match_parent" 
    android:orientation="horizontal">


    <fragment
        android:id="@+id/frameOne"
        android:name="com.tyczj.bowling.BowlersListFragment"
        android:layout_width="300dp"
        android:layout_height="match_parent"
        android:background="@drawable/list_background_holo" />
    
    <fragment android:name="com.tyczj.bowling.BowlerEntryFrag"
        android:id="@+id/frameTwo"
        android:layout_height="match_parent"
        android:layout_width="fill_parent"/>
    
    
</LinearLayout>

*First fragment with the scrollview*
*
*
<?xml version="1.0" encoding="utf-8"?>
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android";
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:background="@drawable/wood_floor" >

<RelativeLayout android:layout_width="match_parent"
    android:layout_height="wrap_content">
    
    <TextView
           android:id="@+id/textView2"
           android:layout_width="wrap_content"
           android:layout_height="wrap_content"
           android:layout_marginLeft="40dp"
           android:layout_marginTop="30dp"
           android:text="Add Bowler"
           android:textAppearance="?android:attr/textAppearanceLarge"
           android:textColor="#33b5e5"
           android:textSize="40dp" />

       <FrameLayout
           android:id="@+id/line"
           android:layout_width="fill_parent"
           android:layout_height="3dp"
           android:layout_alignParentLeft="true"
           android:layout_below="@+id/textView2"
           android:layout_marginLeft="20dp"
           android:layout_marginRight="20dp"
           android:layout_marginTop="8dp"
           android:background="@drawable/ab_solid_custom_blue_inverse_holo" 
>
       </FrameLayout>
       
       <TextView
           android:id="@+id/textView1"
           android:layout_width="wrap_content"
           android:layout_height="wrap_content"
           android:layout_alignLeft="@+id/line"
           android:layout_below="@+id/line"
           android:layout_marginTop="20dp"
           android:text="@string/bNameTV"
           android:textAppearance="?android:attr/textAppearanceMedium" />
       
    
   <EditText
           android:id="@+id/editText1"
           android:layout_width="fill_parent"
           android:layout_height="wrap_content"
           android:layout_below="@+id/line"
           android:layout_marginRight="20dp"
           android:layout_marginLeft="30dp"
           android:layout_toRightOf="@+id/textView1"
           android:inputType="textPersonName" >

           <requestFocus/>

       </EditText>
       
          <EditText
           android:id="@+id/editText2"
           android:layout_width="fill_parent"
           android:layout_height="wrap_content"
           android:layout_below="@+id/editText1"
           android:layout_toRightOf="@+id/textView3"
           android:layout_marginLeft="30dp"
           android:layout_marginRight="20dp"
           android:inputType="textPersonName" >

           <requestFocus/>

       </EditText>
       
   <TextView
           android:id="@+id/textView3"
           android:layout_width="wrap_content"
           android:layout_height="wrap_content"
           android:layout_alignLeft="@+id/line"
           android:layout_below="@+id/textView1"
           android:layout_marginTop="20dp"
           android:text="@string/lNameTV"
           android:textAppearance="?android:attr/textAppearanceMedium" />
   
   <RadioButton
       android:id="@+id/radioButton1"
       android:layout_width="wrap_content"
       android:layout_height="wrap_content"
       android:layout_alignLeft="@+id/textView3"
       android:layout_below="@+id/textView3"
       android:layout_marginTop="15dp"
       android:checked="true"
       android:text="Right Handed" />
   
   <RadioButton
           android:id="@+id/radioButton2"
           android:layout_width="wrap_content"
           android:layout_height="wrap_content"
           android:layout_below="@+id/radioButton1"
           android:layout_alignLeft="@+id/line"
           android:text="Left Handed" />
   
   <Button
           android:id="@+id/done"
           android:layout_width="wrap_content"
           android:layout_height="wrap_content"
           android:layout_below="@+id/radioButton2"
           android:layout_alignParentBottom="true"
           android:layout_alignLeft="@+id/line"
           android:onClick="onDoneClick"
           android:text="@string/done" />
          
       
</RelativeLayout>
</ScrollView>

*The Second fragment view with the scrollview*
*
*
<?xml version="1.0" encoding="utf-8"?>
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android";
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:background="@drawable/wood_floor" >

<RelativeLayout android:layout_width="match_parent"
    android:layout_height="wrap_content">
    
    <TextView
           android:id="@+id/textView2"
           android:layout_width="wrap_content"
           android:layout_height="wrap_content"
           android:layout_marginLeft="40dp"
           android:layout_marginTop="30dp"
           android:text="Add Bowler"
           android:textAppearance="?android:attr/textAppearanceLarge"
           android:textColor="#33b5e5"
           android:textSize="40dp" />

       <FrameLayout
           android:id="@+id/line"
           android:layout_width="fill_parent"
           android:layout_height="3dp"
           android:layout_alignParentLeft="true"
           android:layout_below="@+id/textView2"
           android:layout_marginLeft="20dp"
           android:layout_marginRight="20dp"
           android:layout_marginTop="8dp"
           android:background="@drawable/ab_solid_custom_blue_inverse_holo" 
>
       </FrameLayout>
       
       <TextView
           android:id="@+id/textView1"
           android:layout_width="wrap_content"
           android:layout_height="wrap_content"
           android:layout_alignLeft="@+id/line"
           android:layout_below="@+id/line"
           android:layout_marginTop="20dp"
           android:text="@string/bNameTV"
           android:textAppearance="?android:attr/textAppearanceMedium" />
       
    
   <EditText
           android:id="@+id/editText1"
           android:layout_width="fill_parent"
           android:layout_height="wrap_content"
           android:layout_below="@+id/line"
           android:layout_marginRight="20dp"
           android:layout_marginLeft="30dp"
           android:layout_toRightOf="@+id/textView1"
           android:inputType="textPersonName" >

           <requestFocus/>

       </EditText>
       
          <EditText
           android:id="@+id/editText2"
           android:layout_width="fill_parent"
           android:layout_height="wrap_content"
           android:layout_below="@+id/editText1"
           android:layout_toRightOf="@+id/textView3"
           android:layout_marginLeft="30dp"
           android:layout_marginRight="20dp"
           android:inputType="textPersonName" >

           <requestFocus/>

       </EditText>
       
   <TextView
           android:id="@+id/textView3"
           android:layout_width="wrap_content"
           android:layout_height="wrap_content"
           android:layout_alignLeft="@+id/line"
           android:layout_below="@+id/textView1"
           android:layout_marginTop="20dp"
           android:text="@string/lNameTV"
           android:textAppearance="?android:attr/textAppearanceMedium" />
   
   <RadioButton
       android:id="@+id/radioButton1"
       android:layout_width="wrap_content"
       android:layout_height="wrap_content"
       android:layout_alignLeft="@+id/textView3"
       android:layout_below="@+id/textView3"
       android:layout_marginTop="15dp"
       android:checked="true"
       android:text="Right Handed" />
   
   <RadioButton
           android:id="@+id/radioButton2"
           android:layout_width="wrap_content"
           android:layout_height="wrap_content"
           android:layout_below="@+id/radioButton1"
           android:layout_alignLeft="@+id/line"
           android:text="Left Handed" />
   
   <Button
           android:id="@+id/done"
           android:layout_width="wrap_content"
           android:layout_height="wrap_content"
           android:layout_below="@+id/radioButton2"
           android:layout_alignParentBottom="true"
           android:layout_alignLeft="@+id/line"
           android:onClick="onDoneClick"
           android:text="@string/done" />
          
       
</RelativeLayout>
</ScrollView>

this is how I replace the fragment

    ft.replace(R.id.frameTwo, individual);
ft.addToBackStack(null).commit();

as you can see both scrollviews do have only a single child so I do not 
understand the error

-- 
You received this message because you are subscribed to the Google
Groups "Android Developers" group.
To post to this group, send email to android-developers@googlegroups.com
To unsubscribe from this group, send email to
android-developers+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en

Reply via email to