title: Hopefully a simple Kotlin regarding looping through a recycler
body: <p>I have a recycler in my activity for acrostic poetry. The recycler displays an image of the letters of the word (Stone Age, in this case) and an EditText to enter the acrostic words. What I want to do is read the words that have been entered, so for &quot;Stone Age&quot; I'm creating 8 items in the recycler.</p>
  <p>In order to get the words, I have tried to replicate the steps in this question <a href="https://stackoverflow.com/questions/32811156/how-to-iterate-over-recyclerview-items">How to iterate over RecyclerView items</a>. I think I'm close, but I can't quite get over the line.</p>
  <p>I have this function where I am trying to read the values (at this stage just into the logcat)</p>
  <p>I figured that getChildCount returned the items, but this is logging 2 (or sometimes, oddly, 3) rather than the 8 I would expect, so I'm struggling to understand what I am looping.</p>
  <pre><code>private fun saveTask() {
    var p: String = &quot;&quot;
    Log.d(HWG.TAG, &quot;Children: ${acrosticRecycler.getChildCount().toString()}&quot;)
  
    for (i in 0 until acrosticRecycler.getChildCount()) {
      var holder: AcrosticAdapter.ViewHolder
      if(acrosticRecycler.findViewHolderForAdapterPosition(i) != null) {
          holder = acrosticRecycler.findViewHolderForAdapterPosition(i) as AcrosticAdapter.ViewHolder
          p = holder.txtWord.text.toString()
          Log.d(HWG.TAG, &quot;Word: ${p}&quot;)
      }
  
    }
  }
  </code></pre>
  <p>This is the layout of the recycler</p>
  <pre><code>&lt;?xml version=&quot;1.0&quot; encoding=&quot;utf-8&quot;?&gt;
  &lt;androidx.cardview.widget.CardView xmlns:android=&quot;http://schemas.android.com/apk/res/android&quot;
      xmlns:app=&quot;http://schemas.android.com/apk/res-auto&quot;
      android:layout_width=&quot;match_parent&quot;
      android:layout_height=&quot;wrap_content&quot;
      android:layout_marginRight=&quot;8dp&quot;
      android:layout_marginLeft=&quot;8dp&quot;
      android:layout_marginTop=&quot;8dp&quot;
      android:layout_marginBottom=&quot;4dp&quot;
      app:cardCornerRadius=&quot;4dp&quot;
      app:cardElevation=&quot;6dp&quot;&gt;
  
      &lt;LinearLayout
          android:id=&quot;@+id/llTaskList&quot;
          android:layout_width=&quot;match_parent&quot;
          android:layout_height=&quot;wrap_content&quot;
          android:orientation=&quot;horizontal&quot;
          android:padding=&quot;5dp&quot;&gt;
  
          &lt;ImageView
              android:id=&quot;@+id/imgLetter&quot;
              android:layout_width=&quot;40dp&quot;
              android:layout_height=&quot;40dp&quot;
              android:layout_gravity=&quot;center_vertical&quot;
              android:adjustViewBounds=&quot;true&quot;
              android:cropToPadding=&quot;true&quot;
              android:scaleType=&quot;centerCrop&quot;
              app:srcCompat=&quot;@drawable/icons8_s&quot; /&gt;
  
          &lt;EditText
              android:id=&quot;@+id/txtWord&quot;
              android:layout_width=&quot;match_parent&quot;
              android:layout_height=&quot;wrap_content&quot;
              android:layout_gravity=&quot;center_vertical&quot;
              android:layout_marginStart=&quot;5dp&quot;
              android:layout_marginLeft=&quot;5dp&quot;
              android:hint=&quot;Stone Age&quot;
              android:textAllCaps=&quot;true&quot;
              android:textSize=&quot;18sp&quot;
              android:textStyle=&quot;bold&quot; /&gt;
  
      &lt;/LinearLayout&gt;
  &lt;/androidx.cardview.widget.CardView&gt;
  </code></pre>
  <p>This is the activity in which the recycler sits</p>
  <pre><code>&lt;?xml version=&quot;1.0&quot; encoding=&quot;utf-8&quot;?&gt;
  &lt;androidx.constraintlayout.widget.ConstraintLayout 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;@color/background&quot;
      tools:context=&quot;.TextualTask&quot;&gt;
  
      &lt;androidx.cardview.widget.CardView
          android:layout_width=&quot;match_parent&quot;
          android:layout_height=&quot;wrap_content&quot;
          android:layout_margin=&quot;24dp&quot;
          android:background=&quot;@color/background&quot;
          app:cardCornerRadius=&quot;4dp&quot;
          app:cardElevation=&quot;6dp&quot;
          app:layout_constraintTop_toTopOf=&quot;parent&quot;
          tools:layout_editor_absoluteX=&quot;24dp&quot;&gt;
  
          &lt;LinearLayout
              android:layout_width=&quot;match_parent&quot;
              android:layout_height=&quot;wrap_content&quot;
              android:orientation=&quot;vertical&quot;
              android:padding=&quot;5dp&quot;&gt;
  
              &lt;LinearLayout
                  android:layout_width=&quot;match_parent&quot;
                  android:layout_height=&quot;wrap_content&quot;
                  android:orientation=&quot;horizontal&quot;
                  android:padding=&quot;5dp&quot;&gt;
  
                  &lt;ImageView
                      android:id=&quot;@+id/subjectImage&quot;
                      android:layout_width=&quot;60dp&quot;
                      android:layout_height=&quot;60dp&quot;
                      android:layout_gravity=&quot;center_horizontal&quot;
                      android:adjustViewBounds=&quot;true&quot;
                      android:cropToPadding=&quot;true&quot;
                      android:scaleType=&quot;centerCrop&quot;
                      app:srcCompat=&quot;@drawable/icons8_knowledge_sharing_80&quot; /&gt;
  
                  &lt;LinearLayout
                      android:layout_width=&quot;match_parent&quot;
                      android:layout_height=&quot;wrap_content&quot;
                      android:orientation=&quot;vertical&quot;
                      android:padding=&quot;5dp&quot;&gt;
  
                      &lt;TextView
                          android:id=&quot;@+id/txtTitle&quot;
                          android:layout_width=&quot;wrap_content&quot;
                          android:layout_height=&quot;wrap_content&quot;
                          android:layout_gravity=&quot;center_vertical&quot;
                          android:layout_marginStart=&quot;10dp&quot;
                          android:layout_marginLeft=&quot;15dp&quot;
                          android:text=&quot;Acrostic Poem&quot;
                          android:textAllCaps=&quot;true&quot;
                          android:textSize=&quot;16sp&quot;
                          android:textStyle=&quot;bold&quot; /&gt;
  
                  &lt;/LinearLayout&gt;
  
              &lt;/LinearLayout&gt;
  
              &lt;View
                  android:id=&quot;@+id/divider&quot;
                  android:layout_width=&quot;match_parent&quot;
                  android:layout_height=&quot;2dp&quot;
                  android:layout_margin=&quot;6dp&quot;
                  android:background=&quot;?android:attr/listDivider&quot; /&gt;
  
              &lt;LinearLayout
                  android:layout_width=&quot;match_parent&quot;
                  android:layout_height=&quot;wrap_content&quot;
                  android:orientation=&quot;horizontal&quot;
                  android:padding=&quot;5dp&quot;&gt;
  
                  &lt;TextView
                      android:id=&quot;@+id/txtPreamble&quot;
                      android:layout_width=&quot;match_parent&quot;
                      android:layout_height=&quot;wrap_content&quot;
                      android:layout_marginStart=&quot;10dp&quot;
                      android:layout_marginLeft=&quot;15dp&quot;
                      android:text=&quot;Preamble text&quot;
                      android:textAlignment=&quot;center&quot;
                      android:textSize=&quot;14sp&quot;
                      android:textStyle=&quot;bold|italic&quot; /&gt;
              &lt;/LinearLayout&gt;
  
              &lt;LinearLayout
                  android:layout_width=&quot;match_parent&quot;
                  android:layout_height=&quot;wrap_content&quot;
                  android:orientation=&quot;vertical&quot;
                  android:padding=&quot;5dp&quot;&gt;
  
                  &lt;androidx.cardview.widget.CardView
                      android:id=&quot;@+id/crdWord&quot;
                      android:layout_width=&quot;match_parent&quot;
                      android:layout_height=&quot;wrap_content&quot;
                      android:layout_margin=&quot;24dp&quot;
                      app:cardBackgroundColor=&quot;@color/cardback&quot;
                      app:cardCornerRadius=&quot;4dp&quot;
                      app:cardElevation=&quot;6dp&quot;&gt;
  
                      &lt;LinearLayout
                          android:layout_width=&quot;match_parent&quot;
                          android:layout_height=&quot;wrap_content&quot;
                          android:orientation=&quot;vertical&quot;
                          android:padding=&quot;5dp&quot;&gt;
  
                          &lt;Button
                              android:id=&quot;@+id/btnSubmit&quot;
                              android:layout_width=&quot;match_parent&quot;
                              android:layout_height=&quot;wrap_content&quot;
                              android:layout_margin=&quot;6dp&quot;
                              android:backgroundTint=&quot;@color/start&quot;
                              android:text=&quot;Submit&quot; /&gt;
  
                          &lt;androidx.recyclerview.widget.RecyclerView
                              android:id=&quot;@+id/acrosticRecycler&quot;
                              android:layout_width=&quot;match_parent&quot;
                              android:layout_height=&quot;match_parent&quot;
                              tools:itemCount=&quot;5&quot;
                              tools:listitem=&quot;@layout/acrostic_task&quot; /&gt;
                         
                      &lt;/LinearLayout&gt;
  
                  &lt;/androidx.cardview.widget.CardView&gt;
              &lt;/LinearLayout&gt;
          &lt;/LinearLayout&gt;
      &lt;/androidx.cardview.widget.CardView&gt;
  &lt;/androidx.constraintlayout.widget.ConstraintLayout&gt;
  </code></pre>
  <p>Oddly enough, sometime the for loop gets the values from items 0-2, but sometimes it doesn't. The call to saveTask is made from btnSubmit as I don't need to get the values at the point the user enters them, just when they're happy to submit.</p>
  <p>Could someone point me in the right direction please?</p>