title: programatically add elements to a scrollview gives me Java.Lang.IllegalStateException
body: <p>I'm trying to add textview and progressbar's to a scrollview but it gives me a <code>Java.Lang.IllegalStateException:</code> </p>
  
  <p>I'm using xamarin so this is not java but c# but it's the same principe</p>
  
  <p>here's the code (summarized) :</p>
  
  <pre><code>    SetContentView(Resource.Layout.Usage);
      ScrollView scrollView = FindViewById&lt;ScrollView&gt;(Resource.Id.scrollView1);
      LinearLayout linearLayout = FindViewById&lt;LinearLayout&gt;(Resource.Id.linearLayout2);
  
  while (...){
      TextView textView = new TextView(this);
      textView.Text = "Some text";
      textView.SetTextSize(Android.Util.ComplexUnitType.Sp, 18.0f);
      linearLayout.AddView(textView);
  
      ProgressBar progressBar = new ProgressBar(this, null, Android.Resource.Attribute.ProgressBarStyleHorizontal);
      progressBar.Progress = 25;
      linearLayout.AddView(progressBar);
  }
  
  scrollView.AddView(linearLayout);
  </code></pre>
  
  <p>Stack :</p>
  
  <pre><code>04-15 08:49:00.603 I/MonoDroid( 1389): UNHANDLED EXCEPTION: Java.Lang.IllegalStateException: Exception of type 'Java.Lang.IllegalStateException' was thrown.
  04-15 08:49:00.603 I/MonoDroid( 1389): at Android.Runtime.JNIEnv.CallVoidMethod (intptr,intptr,Android.Runtime.JValue[]) [0x00023] in /Users/builder/data/lanes/monodroid-lion-bigsplash/0e0e51f9/source/monodroid/src/Mono.Android/src/Runtime/JNIEnv.g.cs:368
  04-15 08:49:00.603 I/MonoDroid( 1389): at Android.Views.ViewGroup.AddView (Android.Views.View) [0x0003e] in /Users/builder/data/lanes/monodroid-lion-bigsplash/0e0e51f9/source/monodroid/src/Mono.Android/platforms/android-8/src/generated/Android.Views.ViewGroup.cs:1186
  04-15 08:49:00.603 I/MonoDroid( 1389): at MyOrangeDroid.Usage.OnCreate (Android.OS.Bundle) [0x001be] in c:\Users\clement\Documents\Visual Studio 2012\Projects\MyOrangeAndroid\MyOrangeDroid\Usage.cs:70
  04-15 08:49:00.603 I/MonoDroid( 1389): at Android.App.Activity.n_OnCreate_Landroid_os_Bundle_ (intptr,intptr,intptr) [0x00010] in /Users/builder/data/lanes/monodroid-lion-bigsplash/0e0e51f9/source/monodroid/src/Mono.Android/platforms/android-8/src/generated/Android.App.Activity.cs:1490
  04-15 08:49:00.603 I/MonoDroid( 1389): at (wrapper dynamic-method) object.6c050c56-6d80-48bc-9425-e832938cdfa7 (intptr,intptr,intptr) &lt;IL 0x00017, 0x00043&gt;
  04-15 08:49:00.603 I/MonoDroid( 1389): 
  04-15 08:49:00.603 I/MonoDroid( 1389):   --- End of managed exception stack trace ---
  04-15 08:49:00.603 I/MonoDroid( 1389): java.lang.IllegalStateException: ScrollView can host only one direct child
  04-15 08:49:00.603 I/MonoDroid( 1389):  at android.widget.ScrollView.addView(ScrollView.java:211)
  04-15 08:49:00.603 I/MonoDroid( 1389):  at myorangedroid.Usage.n_onCreate(Native Method)
  04-15 08:49:00.603 I/MonoDroid( 1389):  at myorangedroid.Usage.onCreate(Usage.java:28)
  04-15 08:49:00.603 I/MonoDroid( 1389):  at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1047)
  04-15 08:49:00.603 I/MonoDroid( 1389):  at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1611)
  04-15 08:49:00.603 I/MonoDroid( 1389):  at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:1663)
  04-15 08:49:00.603 I/MonoDroid( 1389):  at android.app.ActivityThread.access$1500(ActivityThread.java:117)
  04-15 08:49:00.603 I/MonoDroid( 1389):  at android.app.ActivityThread$H.handleMessage(ActivityThread.java:931)
  04-15 08:49:00.603 I/MonoDroid( 1389):  at android.os.Handler.dispatchMessage(Handler.java:99)
  04-15 08:49:00.603 I/MonoDroid( 1389):  at android.os.Looper.loop(Looper.java:123)
  04-15 08:49:00.603 I/MonoDroid( 1389):  at android.app.ActivityThread.main(ActivityThread.java:3683)
  04-15 08:49:00.603 I/MonoDroid( 1389):  at java.lang.reflect.Method.invokeNative(Native Method)
  04-15 08:49:00.603 I/MonoDroid( 1389):  at java.lang.reflect.Method.invoke(Method.java:507)
  04-15 08:49:00.603 I/MonoDroid( 1389):  at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:839)
  04-15 08:49:00.603 I/MonoDroid( 1389):  at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:597)
  04-15 08:49:00.603 I/MonoDroid( 1389):  at dalvik.system.NativeStart.main(Native Method)
  In mgmain JNI_OnLoad
  04-15 08:49:01.503 W/dalvikvm( 1389): JNI WARNING: JNI method called with exception raised
  04-15 08:49:01.503 W/dalvikvm( 1389):              in Lmyorangedroid/Usage;.n_onCreate (Landroid/os/Bundle;)V (CallObjectMethod)
  04-15 08:49:01.503 W/dalvikvm( 1389): Pending exception is:
  04-15 08:49:01.503 I/dalvikvm( 1389): Ljava/lang/IllegalStateException;: ScrollView can host only one direct child
  04-15 08:49:01.513 I/dalvikvm( 1389):   (no stack trace data found)
  04-15 08:49:01.513 I/dalvikvm( 1389): "main" prio=5 tid=1 NATIVE
  04-15 08:49:01.513 I/dalvikvm( 1389):   | group="main" sCount=0 dsCount=0 obj=0x4001f1a8 self=0xce48
  04-15 08:49:01.513 I/dalvikvm( 1389):   | sysTid=1389 nice=0 sched=0/0 cgrp=default handle=-1345006528
  04-15 08:49:01.513 I/dalvikvm( 1389):   | schedstat=( 7098128094 1495743800 310 )
  04-15 08:49:01.513 I/dalvikvm( 1389):   at myorangedroid.Usage.n_onCreate(Native Method)
  04-15 08:49:01.523 I/dalvikvm( 1389):   at myorangedroid.Usage.onCreate(Usage.java:28)
  04-15 08:49:01.523 I/dalvikvm( 1389):   at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1047)
  04-15 08:49:01.523 I/dalvikvm( 1389):   at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1611)
  04-15 08:49:01.523 I/dalvikvm( 1389):   at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:1663)
  04-15 08:49:01.523 I/dalvikvm( 1389):   at android.app.ActivityThread.access$1500(ActivityThread.java:117)
  04-15 08:49:01.523 I/dalvikvm( 1389):   at android.app.ActivityThread$H.handleMessage(ActivityThread.java:931)
  04-15 08:49:01.523 I/dalvikvm( 1389):   at android.os.Handler.dispatchMessage(Handler.java:99)
  04-15 08:49:01.523 I/dalvikvm( 1389):   at android.os.Looper.loop(Looper.java:123)
  04-15 08:49:01.523 I/dalvikvm( 1389):   at android.app.ActivityThread.main(ActivityThread.java:3683)
  04-15 08:49:01.523 I/dalvikvm( 1389):   at java.lang.reflect.Method.invokeNative(Native Method)
  04-15 08:49:01.523 I/dalvikvm( 1389):   at java.lang.reflect.Method.invoke(Method.java:507)
  04-15 08:49:01.523 I/dalvikvm( 1389):   at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:839)
  04-15 08:49:01.523 I/dalvikvm( 1389):   at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:597)
  04-15 08:49:01.523 I/dalvikvm( 1389):   at dalvik.system.NativeStart.main(Native Method)
  04-15 08:49:01.523 I/dalvikvm( 1389): 
  04-15 08:49:01.523 E/dalvikvm( 1389): VM aborting
  04-15 08:49:01.533 I/mono    ( 1389): Stacktrace:
  04-15 08:49:01.533 I/mono    ( 1389): 
  04-15 08:49:01.533 I/mono    ( 1389):   at Android.Runtime.JNIEnv.CallObjectMethod (intptr,intptr) [0x00000] in /Users/builder/data/lanes/monodroid-lion-bigsplash/0e0e51f9/source/monodroid/src/Mono.Android/src/Runtime/JNIEnv.g.cs:129
  04-15 08:49:01.533 I/mono    ( 1389):   at Java.Lang.Throwable.get_Message () [0x0003e] in /Users/builder/data/lanes/monodroid-lion-bigsplash/0e0e51f9/source/monodroid/src/Mono.Android/platforms/android-8/src/generated/Java.Lang.Throwable.cs:195
  04-15 08:49:01.533 I/mono    ( 1389):   at (wrapper runtime-invoke) &lt;Module&gt;.runtime_invoke_object__this__ (object,intptr,intptr,intptr) &lt;IL 0x00050, 0xffffffff&gt;
  Unhandled Exception:
  
  Java.Lang.IllegalStateException: 
  </code></pre>
  
  <p>Thanks for the help/read :-)</p>