-1

I have a scroll view inside which there is a fragment and when i click on a button I want to switch fragment to another one. I tried Fragment Transaction but I am getting this error

java.lang.IllegalStateException: ScrollView can host only one direct child

Code :

Search search = new Search();
android.support.v4.app.FragmentTransaction transaction = getSupportFragmentManager().beginTransaction();
transaction.replace(R.id.scrollView,search).commit();
gmetax
  • 3,853
  • 2
  • 31
  • 45
Tony30
  • 51
  • 1
  • 10

1 Answers1

1

You have to use a FrameLayout as your ScrollView's child and then use the transaction to change the fragment

xml(partial):

<ScrollView>
   <FrameLayout
    android:id="@+id/frameLayout"/>
</ScrollView>

and then with java

getSupportFragmentManager().beginTransaction().replace(R.id.frameLayout,new Search()).commit();
gmetax
  • 3,853
  • 2
  • 31
  • 45