title: My recursive function is not creating TextInputLayouts
body: <p>i am creating an app for someone. In that app, there is an activity where he can save his charge fees by entering the name and the amount.</p>
  <p><a href="https://i.stack.imgur.com/wrCjS.jpg" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/wrCjS.jpg" alt="enter image description here" /></a></p>
  <p>For that i'm using two TextInputLayouts. The first TextInputLayout has an inputType value that is &quot;text&quot; and imeOptions is &quot;actionNext&quot;. The second one has an inputType value that is &quot;number&quot; and imeOptions is &quot;actionDone&quot;.</p>
  <pre><code>&lt;com.google.android.material.textfield.TextInputLayout
      android:id=&quot;@+id/nom&quot;
      android:layout_width=&quot;match_parent&quot;
      android:layout_height=&quot;wrap_content&quot;
      android:layout_below=&quot;@+id/toolbar&quot;
      android:layout_marginTop=&quot;20dp&quot;
      android:layout_marginHorizontal=&quot;30dp&quot;
      style=&quot;@style/Widget.MaterialComponents.TextInputLayout.OutlinedBox&quot;
      app:boxCornerRadiusTopStart=&quot;7dp&quot;
      app:endIconMode=&quot;clear_text&quot;
      app:boxStrokeColor=&quot;#25B1EF&quot;
      app:hintTextColor=&quot;#25B1EF&quot;
      app:errorEnabled=&quot;true&quot;&gt;
  
  &lt;com.google.android.material.textfield.TextInputEditText
      android:layout_width=&quot;match_parent&quot;
      android:layout_height=&quot;wrap_content&quot;
      android:hint=&quot;Nom&quot;
      android:textSize=&quot;20sp&quot;
      android:inputType=&quot;text&quot;
      android:imeOptions=&quot;actionNext&quot;/&gt;
  
  &lt;/com.google.android.material.textfield.TextInputLayout&gt;
  
  &lt;com.google.android.material.textfield.TextInputLayout
      android:id=&quot;@+id/argent&quot;
      android:layout_width=&quot;match_parent&quot;
      android:layout_height=&quot;wrap_content&quot;
      android:layout_below=&quot;@+id/nom&quot;
      android:layout_marginTop=&quot;20dp&quot;
      android:layout_marginHorizontal=&quot;30dp&quot;
      style=&quot;@style/Widget.MaterialComponents.TextInputLayout.OutlinedBox&quot;
      app:boxCornerRadiusTopStart=&quot;7dp&quot;
      app:endIconMode=&quot;clear_text&quot;
      app:boxStrokeColor=&quot;#25B1EF&quot;
      app:hintTextColor=&quot;#25B1EF&quot;
      app:errorEnabled=&quot;true&quot;&gt;
  
  &lt;com.google.android.material.textfield.TextInputEditText
      android:layout_width=&quot;match_parent&quot;
      android:layout_height=&quot;wrap_content&quot;
      android:hint=&quot;prix total&quot;
      android:textSize=&quot;20sp&quot;
      android:inputType=&quot;number&quot;
      android:imeOptions=&quot;actionDone&quot;/&gt;
  
  &lt;/com.google.android.material.textfield.TextInputLayout&gt;
  </code></pre>
  <p>So, when he wants to add a charge fee, it will be like this :</p>
  <p><a href="https://i.stack.imgur.com/WJti7.jpg" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/WJti7.jpg" alt="enter image description here" /></a></p>
  <p>Sometimes, he might need to save more than one charge. In that case, I prepared 2 more TextInputLayout Fields (new_depense_row.xml) that will be created programmatically whenever imeOptions is &quot;actionDone&quot;. A function called <code>addView()</code> is responsible of creating the views.</p>
  <pre><code>&lt;?xml version=&quot;1.0&quot; encoding=&quot;utf-8&quot;?&gt;
  &lt;RelativeLayout xmlns:android=&quot;http://schemas.android.com/apk/res/android&quot;
      android:layout_width=&quot;match_parent&quot;
      android:layout_height=&quot;match_parent&quot;
      xmlns:app=&quot;http://schemas.android.com/apk/res-auto&quot;&gt;
  
      &lt;com.google.android.material.textfield.TextInputLayout
          android:id=&quot;@+id/nom&quot;
          android:layout_width=&quot;match_parent&quot;
          android:layout_height=&quot;wrap_content&quot;
          android:layout_marginTop=&quot;20dp&quot;
          android:layout_marginHorizontal=&quot;30dp&quot;
          style=&quot;@style/Widget.MaterialComponents.TextInputLayout.OutlinedBox&quot;
          app:boxCornerRadiusTopStart=&quot;7dp&quot;
          app:endIconMode=&quot;clear_text&quot;
          app:boxStrokeColor=&quot;#25B1EF&quot;
          app:hintTextColor=&quot;#25B1EF&quot;
          app:errorEnabled=&quot;true&quot;&gt;
  
      &lt;com.google.android.material.textfield.TextInputEditText
          android:layout_width=&quot;match_parent&quot;
          android:layout_height=&quot;wrap_content&quot;
          android:hint=&quot;Nom&quot;
          android:textSize=&quot;20sp&quot;
          android:inputType=&quot;text&quot;
          android:imeOptions=&quot;actionNext&quot;/&gt;
  
      &lt;/com.google.android.material.textfield.TextInputLayout&gt;
  
      &lt;com.google.android.material.textfield.TextInputLayout
          android:id=&quot;@+id/argent&quot;
          android:layout_width=&quot;match_parent&quot;
          android:layout_height=&quot;wrap_content&quot;
          android:layout_below=&quot;@+id/nom&quot;
          android:layout_marginTop=&quot;20dp&quot;
          android:layout_marginHorizontal=&quot;30dp&quot;
          style=&quot;@style/Widget.MaterialComponents.TextInputLayout.OutlinedBox&quot;
          app:boxCornerRadiusTopStart=&quot;7dp&quot;
          app:endIconMode=&quot;clear_text&quot;
          app:boxStrokeColor=&quot;#25B1EF&quot;
          app:hintTextColor=&quot;#25B1EF&quot;
          app:errorEnabled=&quot;true&quot;&gt;
  
      &lt;com.google.android.material.textfield.TextInputEditText
          android:layout_width=&quot;match_parent&quot;
          android:layout_height=&quot;wrap_content&quot;
          android:hint=&quot;prix total&quot;            
          android:textSize=&quot;20sp&quot;
          android:inputType=&quot;number&quot;
          android:imeOptions=&quot;actionDone&quot;/&gt;
  
      &lt;/com.google.android.material.textfield.TextInputLayout&gt;
  
  &lt;/RelativeLayout&gt;
  
  
  nameInputLayout = findViewById(R.id.nom);
  argentInputLayout = findViewById(R.id.argent);
  LinearLayout layoutNewDepenses = findViewById(R.id.layout_new_depenses);
  
  EditText editText = argentInputLayout.getEditText();
  editText.setOnEditorActionListener((v, actionId, event) -&gt; {
      boolean handled = false;
      if (actionId == EditorInfo.IME_ACTION_DONE) {
          addView();
          handled = true;
      }
      return handled;
  });
      
  
  private void addView() {
  
      final View cricketerView = getLayoutInflater().inflate(R.layout.new_depense_row,null,false);
      TextInputLayout nameInputLayout = findViewById(R.id.nom);
      TextInputLayout argentInputLayout = findViewById(R.id.argent);
  
      nameInputLayout.requestFocus();
  
      editText = argentInputLayout.getEditText();
      editText.setOnEditorActionListener((v, actionId, event) -&gt; {
          boolean handled = false;
          if (actionId == EditorInfo.IME_ACTION_DONE) {
              this.addView();
              handled = true;
          }
          return handled;
      });
  
      layoutNewDepenses.addView(cricketerView);
  
  }
  </code></pre>
  <p>When the second TextInputLayout Field for entering the amount has the focus, instead of clicking the save button (Enregistrer), he has to click on the carriage return button of the keyboard (it's the arrow that's under the delete arrow). After clicking, two Text Fields will be added like this :</p>
  <p><a href="https://i.stack.imgur.com/ucVu6.jpg" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/ucVu6.jpg" alt="enter image description here" /></a></p>
  <p><a href="https://i.stack.imgur.com/QERF1.jpg" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/QERF1.jpg" alt="enter image description here" /></a></p>
  <p>I forgot to mention something. Only the first two TextInputLayout Fields are in the layout of the activity. The other TextInputLayout Fields that are created programmatically are in another file named new_depense_row.xml. Whenever imeOptions is &quot;actionDone&quot;, that file is deserialized and it's added to a LinearLayout view that's part of the layout of activity :</p>
  <pre><code>&lt;LinearLayout
      android:id=&quot;@+id/layout_new_depenses&quot;
      android:layout_width=&quot;match_parent&quot;
      android:layout_height=&quot;wrap_content&quot;
      android:orientation=&quot;vertical&quot;
      android:layout_below=&quot;@id/argent&quot;
      android:layout_marginTop=&quot;25dp&quot;/&gt;
  </code></pre>
  <p>I met two problems :
  First, the Text Field for the name has the focus when it's created programmatically even when i requested it.</p>
  <p>The second one is that the views are created only once. After the first two TextInputLayout Fields are created programmatically, it stopps there. It means that for now on, i can add only 2 charge fees and i can not add more. But i don't want that.</p>
  <p>I hope i make my self clear. Can somebody help me ?</p>
  <p>Here is the code for all the files.</p>
  <p>Layout activity : activity_add_argent.xml</p>
  <pre><code>&lt;?xml version=&quot;1.0&quot; encoding=&quot;utf-8&quot;?&gt;
  &lt;RelativeLayout
      android:id=&quot;@+id/rootView&quot;
      xmlns:android=&quot;http://schemas.android.com/apk/res/android&quot;
      xmlns:app=&quot;http://schemas.android.com/apk/res-auto&quot;
      xmlns:tools=&quot;http://schemas.android.com/tools&quot;
      android:layout_width=&quot;match_parent&quot;
      android:layout_height=&quot;match_parent&quot;
      android:background=&quot;@android:color/holo_blue_bright&quot;
      tools:context=&quot;.Controllers.Activities.AddChargeActivity&quot;&gt;
  
  &lt;!-- Toolbar --&gt;
  &lt;include
      layout=&quot;@layout/toolbar_layout&quot; /&gt;
  
  &lt;com.google.android.material.textfield.TextInputLayout
      android:id=&quot;@+id/nom&quot;
      android:layout_width=&quot;match_parent&quot;
      android:layout_height=&quot;wrap_content&quot;
      android:layout_below=&quot;@+id/toolbar&quot;
      android:layout_marginTop=&quot;20dp&quot;
      android:layout_marginHorizontal=&quot;30dp&quot;
      style=&quot;@style/Widget.MaterialComponents.TextInputLayout.OutlinedBox&quot;
      app:boxCornerRadiusTopStart=&quot;7dp&quot;
      app:endIconMode=&quot;clear_text&quot;
      app:boxStrokeColor=&quot;#25B1EF&quot;
      app:hintTextColor=&quot;#25B1EF&quot;
      app:errorEnabled=&quot;true&quot;&gt;
  
  &lt;com.google.android.material.textfield.TextInputEditText
      android:layout_width=&quot;match_parent&quot;
      android:layout_height=&quot;wrap_content&quot;
      android:hint=&quot;Nom&quot;
      android:textSize=&quot;20sp&quot;
      android:inputType=&quot;text&quot;
      android:imeOptions=&quot;actionNext&quot;/&gt;
  
  &lt;/com.google.android.material.textfield.TextInputLayout&gt;
  
  &lt;com.google.android.material.textfield.TextInputLayout
      android:id=&quot;@+id/argent&quot;
      android:layout_width=&quot;match_parent&quot;
      android:layout_height=&quot;wrap_content&quot;
      android:layout_below=&quot;@+id/nom&quot;
      android:layout_marginTop=&quot;20dp&quot;
      android:layout_marginHorizontal=&quot;30dp&quot;
      style=&quot;@style/Widget.MaterialComponents.TextInputLayout.OutlinedBox&quot;
      app:boxCornerRadiusTopStart=&quot;7dp&quot;
      app:endIconMode=&quot;clear_text&quot;
      app:boxStrokeColor=&quot;#25B1EF&quot;
      app:hintTextColor=&quot;#25B1EF&quot;
      app:errorEnabled=&quot;true&quot;&gt;
  
  &lt;com.google.android.material.textfield.TextInputEditText
      android:layout_width=&quot;match_parent&quot;
      android:layout_height=&quot;wrap_content&quot;
      android:hint=&quot;prix total&quot;
      android:textSize=&quot;20sp&quot;
      android:inputType=&quot;number&quot;
      android:imeOptions=&quot;actionDone&quot;/&gt;
  
  &lt;/com.google.android.material.textfield.TextInputLayout&gt;
  
  &lt;LinearLayout
      android:id=&quot;@+id/layout_new_depenses&quot;
      android:layout_width=&quot;match_parent&quot;
      android:layout_height=&quot;wrap_content&quot;
      android:orientation=&quot;vertical&quot;
      android:layout_below=&quot;@id/argent&quot;
      android:layout_marginTop=&quot;25dp&quot;/&gt;
  
  &lt;Button
      android:id=&quot;@+id/save_argent&quot;
      android:layout_width=&quot;match_parent&quot;
      android:layout_height=&quot;wrap_content&quot;
      android:layout_marginHorizontal=&quot;30dp&quot;
      android:layout_marginTop=&quot;@android:dimen/app_icon_size&quot;
      android:text=&quot;Enregistrer&quot;
      android:layout_below=&quot;@+id/layout_new_depenses&quot; /&gt;
  
  &lt;/RelativeLayout&gt;
  </code></pre>
  <p>Activity File : AddChargeActivity</p>
  <pre><code>public class AddChargeActivity extends AppCompatActivity {
  
      EditText editText;
      TextInputLayout nameInputLayout, argentInputLayout;
      RelativeLayout rootView;
      LinearLayout layoutNewDepenses;
  
      @Override
      protected void onCreate(Bundle savedInstanceState) {
          super.onCreate(savedInstanceState);
          setContentView(R.layout.activity_add_argent);
  
          rootView = findViewById(R.id.rootView);
          nameInputLayout = findViewById(R.id.nom);
          argentInputLayout = findViewById(R.id.argent);
          layoutNewDepenses = findViewById(R.id.layout_new_depenses);
  
          editText = argentInputLayout.getEditText();
          editText.setOnEditorActionListener((v, actionId, event) -&gt; {
              boolean handled = false;
              if (actionId == EditorInfo.IME_ACTION_DONE) {
                  addView();
                  handled = true;
              }
              return handled;
          });
  
          Button saveKhatBtn = findViewById(R.id.save_argent);
          saveKhatBtn.setOnClickListener(v -&gt; startProcess());
      }
  
      private void addView() {
  
          final View cricketerView = getLayoutInflater().inflate(R.layout.new_depense_row,null,false);
          TextInputLayout nameInputLayout = findViewById(R.id.nom);
          TextInputLayout argentInputLayout = findViewById(R.id.argent);
  
          nameInputLayout.requestFocus();
  
          editText = argentInputLayout.getEditText();
          editText.setOnEditorActionListener((v, actionId, event) -&gt; {
              boolean handled = false;
              if (actionId == EditorInfo.IME_ACTION_DONE) {
                  this.addView();
                  handled = true;
              }
              return handled;
          });
  
          layoutNewDepenses.addView(cricketerView);
  
      }
  
      private void startProcess() {
          if (!validateString(nameInputLayout, &quot;Renseignez le nom&quot;) | !validateString(argentInputLayout, &quot;Renseignez l'argent pris&quot;))
              return;
  
          ProgressDialog progressDialog = configureProgression(this);
  
          String nameClient = getInputs(nameInputLayout);
          String argent = getInputs(argentInputLayout);
  
          Map argentMap = new HashMap();
          argentMap.put(&quot;name&quot;, nameClient);
          argentMap.put(&quot;argent&quot;, argent);
  
          String id = nameClient + &quot;-&quot; + argent;
  
          getDayOnlyDocumentReference(choosenYear, choosenMonth, choosenDay).get().addOnCompleteListener(task -&gt; {
              Total totaux = task.getResult().toObject(Total.class);
  
              if (totaux != null) {
                  getDateCollectionReference(choosenDate).document(CHARGES)
                      .collection(CHARGES).document(id).set(argentMap)
                      .addOnSuccessListener(unused -&gt; {
  
                      int nouvelleDepense = Integer.parseInt(totaux.getTotal_charge());
                      nouvelleDepense += Integer.parseInt(argent);
  
                      int resultat_1 = Integer.parseInt(totaux.getResultat_1());
                      resultat_1 -= Integer.parseInt(argent);
  
                      int resultat_final = Integer.parseInt(totaux.getResultat_final());
                      resultat_final -= Integer.parseInt(argent);
  
                      Map updateMap = new HashMap();
                      updateMap.put(TOTAL_CHARGE, String.valueOf(nouvelleDepense));
                      updateMap.put(RESULTAT_1, String.valueOf(resultat_1));
                      updateMap.put(RESULTAT_FINAL, String.valueOf(resultat_final));
  
                      getDayOnlyDocumentReference(choosenYear, choosenMonth, choosenDay).update(updateMap).addOnSuccessListener(o -&gt; {
                          nameInputLayout.getEditText().setText(&quot;&quot;);
                          argentInputLayout.getEditText().setText(&quot;&quot;);
                          progressDialog.dismiss();
                          showDoneSnackbar(this, rootView);
                      });
                  }).addOnFailureListener(e -&gt; {
                      progressDialog.dismiss();
                      showProblemSnackbar(this, rootView);
                  });
              } else {
                  progressDialog.dismiss();
                  Snackbar.make(this, rootView, &quot;Vous devez d'abord ajouter le stock de khat de la journée !&quot;, Snackbar.LENGTH_LONG)
                  .setBackgroundTint(Color.RED).show();
              }
          }).addOnFailureListener(e -&gt; {
              progressDialog.dismiss();
              showProblemSnackbar(this, rootView);
          });
      }
  }
  </code></pre>
  <p>Layout for The two TextInputLayout Fields : new_depense_row.xml</p>
  <pre><code>&lt;?xml version=&quot;1.0&quot; encoding=&quot;utf-8&quot;?&gt;
  &lt;RelativeLayout xmlns:android=&quot;http://schemas.android.com/apk/res/android&quot;
      android:layout_width=&quot;match_parent&quot;
      android:layout_height=&quot;match_parent&quot;
      xmlns:app=&quot;http://schemas.android.com/apk/res-auto&quot;&gt;
  
      &lt;com.google.android.material.textfield.TextInputLayout
          android:id=&quot;@+id/nom&quot;
          android:layout_width=&quot;match_parent&quot;
          android:layout_height=&quot;wrap_content&quot;
          android:layout_marginTop=&quot;20dp&quot;
          android:layout_marginHorizontal=&quot;30dp&quot;
          style=&quot;@style/Widget.MaterialComponents.TextInputLayout.OutlinedBox&quot;
          app:boxCornerRadiusTopStart=&quot;7dp&quot;
          app:endIconMode=&quot;clear_text&quot;
          app:boxStrokeColor=&quot;#25B1EF&quot;
          app:hintTextColor=&quot;#25B1EF&quot;
          app:errorEnabled=&quot;true&quot;&gt;
  
      &lt;com.google.android.material.textfield.TextInputEditText
          android:layout_width=&quot;match_parent&quot;
          android:layout_height=&quot;wrap_content&quot;
          android:hint=&quot;Nom&quot;
          android:textSize=&quot;20sp&quot;
          android:inputType=&quot;text&quot;
          android:imeOptions=&quot;actionNext&quot;/&gt;
  
      &lt;/com.google.android.material.textfield.TextInputLayout&gt;
  
      &lt;com.google.android.material.textfield.TextInputLayout
          android:id=&quot;@+id/argent&quot;
          android:layout_width=&quot;match_parent&quot;
          android:layout_height=&quot;wrap_content&quot;
          android:layout_below=&quot;@+id/nom&quot;
          android:layout_marginTop=&quot;20dp&quot;
          android:layout_marginHorizontal=&quot;30dp&quot;
          style=&quot;@style/Widget.MaterialComponents.TextInputLayout.OutlinedBox&quot;
          app:boxCornerRadiusTopStart=&quot;7dp&quot;
          app:endIconMode=&quot;clear_text&quot;
          app:boxStrokeColor=&quot;#25B1EF&quot;
          app:hintTextColor=&quot;#25B1EF&quot;
          app:errorEnabled=&quot;true&quot;&gt;
  
      &lt;com.google.android.material.textfield.TextInputEditText
          android:layout_width=&quot;match_parent&quot;
          android:layout_height=&quot;wrap_content&quot;
          android:hint=&quot;prix total&quot;
          android:textSize=&quot;20sp&quot;
          android:inputType=&quot;number&quot;
          android:imeOptions=&quot;actionDone&quot;/&gt;
  
      &lt;/com.google.android.material.textfield.TextInputLayout&gt;
  
  &lt;/RelativeLayout&gt;
  </code></pre>