title: Adding TextInputLayout and EditText dynamically (binding)
body: <p>I want to add a new EditText within a TextInputLayout just like how they are added statically in the xml file. (So at the beggining there are two TextInputLayouts and when user press the button it should add new ones). I saw other questions and i know it's about parent layout, but i can't make it work. By the way i'm using binding. In my case, parent should be ScrollView, i think. For the EditText i tried both RelativeLayout and LinearLayout but launches error in any case. </p>
  
  <p>Here the xml file.</p>
  
  <pre><code>&lt;?xml version="1.0" encoding="utf-8"?&gt;
  &lt;layout xmlns:android="http://schemas.android.com/apk/res/android"
      xmlns:app="http://schemas.android.com/apk/res-auto"
      xmlns:tools="http://schemas.android.com/tools"&gt;
  
      &lt;ScrollView
          android:layout_width="match_parent"
          android:layout_height="match_parent"
          android:id="@+id/scrollView"&gt;
  
          &lt;RelativeLayout
              android:id="@+id/activity_multi_opt_poll"
              android:layout_width="match_parent"
              android:layout_height="match_parent"
              android:paddingBottom="@dimen/activity_vertical_margin"
              android:paddingLeft="@dimen/activity_horizontal_margin"
              android:paddingRight="@dimen/activity_horizontal_margin"
              android:paddingTop="@dimen/activity_vertical_margin"
              tools:context="com.xyz.MyApp.EntryActivity"&gt;
  
              &lt;android.support.design.widget.TextInputLayout
                  android:id="@+id/nameInputLayout"
                  android:layout_width="match_parent"
                  android:layout_height="wrap_content"
                  android:hint="Name"&gt;
  
                  &lt;android.support.design.widget.TextInputEditText
                      android:id="@+id/nameEditText"
                      android:layout_width="match_parent"
                      android:layout_height="wrap_content" /&gt;
              &lt;/android.support.design.widget.TextInputLayout&gt;
  
              &lt;android.support.design.widget.TextInputLayout
                  android:id="@+id/questionInputLayout"
                  android:layout_width="match_parent"
                  android:layout_height="wrap_content"
                  android:layout_below="@id/nameInputLayout"
                  android:hint="Question"&gt;
  
                  &lt;android.support.design.widget.TextInputEditText
                      android:id="@+id/questionEditText"
                      android:layout_width="match_parent"
                      android:layout_height="wrap_content" /&gt;
              &lt;/android.support.design.widget.TextInputLayout&gt;
  
              &lt;android.support.design.widget.TextInputLayout
                  android:id="@+id/opt1InputLayout"
                  android:layout_width="match_parent"
                  android:layout_height="wrap_content"
                  android:layout_below="@id/questionInputLayout"
                  android:hint="1. Option"&gt;
  
                  &lt;android.support.design.widget.TextInputEditText
                      android:id="@+id/opt1EditText"
                      android:layout_width="match_parent"
                      android:layout_height="wrap_content" /&gt;
              &lt;/android.support.design.widget.TextInputLayout&gt;
  
  
              &lt;android.support.design.widget.TextInputLayout
                  android:id="@+id/opt2InputLayout"
                  android:layout_width="match_parent"
                  android:layout_height="wrap_content"
                  android:layout_below="@id/opt1InputLayout"
                  android:hint="2. Option"&gt;
  
                  &lt;android.support.design.widget.TextInputEditText
                      android:id="@+id/opt2EditText"
                      android:layout_width="match_parent"
                      android:layout_height="wrap_content" /&gt;
              &lt;/android.support.design.widget.TextInputLayout&gt;
  
              &lt;android.support.design.widget.FloatingActionButton
                  android:layout_width="wrap_content"
                  android:layout_height="wrap_content"
                  android:clickable="true"
                  app:fabSize="normal"
                  app:srcCompat="@android:drawable/ic_input_add"
                  android:id="@+id/addFAB"
                  android:layout_marginEnd="21dp"
                  android:layout_below="@+id/opt2InputLayout"
                  android:layout_alignParentEnd="true" /&gt;
          &lt;/RelativeLayout&gt; 
      &lt;/ScrollView&gt;
  &lt;/layout&gt;
  </code></pre>
  
  <p>And the function to add new </p>
  
  <pre><code>public class EntryActivity extends AppCompatActivity {
      private ActivityEntryBinding binding;
      private List optionsViews = new ArrayList();
      private int count = 3;
  
      @Override
      protected void onCreate(Bundle savedInstanceState) {
          binding = DataBindingUtil.setContentView(this, R.layout.activity_entry);
  
  
          binding.addFAB.setOnClickListener(new View.OnClickListener() {
              @Override
              public void onClick(View view) {
                  binding.scrollView.addView(createNewOptionEntry());
  
              }
          });
      }
  
      private TextInputLayout createNewOptionEntry() {
  
          ScrollView.LayoutParams lparams = new ScrollView.LayoutParams(
                  ScrollView.LayoutParams.MATCH_PARENT, ScrollView.LayoutParams.MATCH_PARENT);
  
          TextInputLayout textInputLayout = new TextInputLayout(this);
          textInputLayout.setLayoutParams(lparams);
          textInputLayout.setHint(count++ + ". Option");
  
  
          LinearLayout.LayoutParams lparams2 = new LinearLayout.LayoutParams(
                  LinearLayout.LayoutParams.MATCH_PARENT, LinearLayout.LayoutParams.WRAP_CONTENT);
  
          final TextInputEditText editText = new TextInputEditText(this);
          editText.setLayoutParams(lparams2);
          int id = View.generateViewId();
          /*to be able to get dynamically generated editText's input*/
          optionsViews.add(id);
          editText.setId(id);
  
          textInputLayout.addView(editText, lparams);
  
          return textInputLayout;
      }
  
  
  }
  </code></pre>
  
  <p>at line textInputLayout.addView(editText, lparams) gives me error:</p>
  
  <pre><code> E/AndroidRuntime: FATAL EXCEPTION: main
   Process: mattoncino.pollo, PID: 23572
   java.lang.ClassCastException: android.widget.FrameLayout$LayoutParams cannot be cast to android.widget.LinearLayout$LayoutParams
     at android.support.design.widget.TextInputLayout.updateInputLayoutMargins(TextInputLayout.java:371)
     at android.support.design.widget.TextInputLayout.addView(TextInputLayout.java:271)
     at android.view.ViewGroup.addView(ViewGroup.java:3540)
     at mattoncino.pollo.MultiOptPollActivity.createNewOptionEntry(MultiOptPollActivity.java:95)
     at mattoncino.pollo.MultiOptPollActivity.access$000(MultiOptPollActivity.java:27)
     at mattoncino.pollo.MultiOptPollActivity$1.onClick(MultiOptPollActivity.java:48)
     at android.view.View.performClick(View.java:4463)
     at android.view.View$PerformClick.run(View.java:18770)
     at android.os.Handler.handleCallback(Handler.java:808)
     at android.os.Handler.dispatchMessage(Handler.java:103)
     at android.os.Looper.loop(Looper.java:193)
     at android.app.ActivityThread.main(ActivityThread.java:5333)
     at java.lang.reflect.Method.invokeNative(Native Method)
     at java.lang.reflect.Method.invoke(Method.java:515)
     at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:824)
     at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:640)
     at dalvik.system.NativeStart.main(Native Method)
  </code></pre>