title: Get ListView children that are not in view
body: <p>For an App I am working on, I'm trying to get the children of a ListView. To do this I have the following piece of code:</p>
  
  <pre><code>View listItem = mListView.getChildAt(i);
  </code></pre>
  
  <p>However, this only works for children that are in view. I need to also reach the children that are not in view. How would I do this?</p>
  
  <p><strong>EDIT:</strong></p>
  
  <p>Comparing the suggested methods to the one I was already using I find the following:</p>
  
  <pre><code>RelativeLayout listItem1 = (RelativeLayout) mListView.getAdapter().getView(i, null, mListView);
  RelativeLayout listItem2 = (RelativeLayout) mListView.getChildAt(i);
  Log.d("Checks", "listItem1: " + listItem1);
  Log.d("Checks", "listItem2: " + listItem2);
  
  08-27 14:16:56.628: D/Checks(15025): listItem1: android.widget.RelativeLayout@2c5f2920
  08-27 14:16:56.628: D/Checks(15025): listItem2: android.widget.RelativeLayout@2c06d938
  08-27 14:16:56.628: D/Checks(15025): listItem1: android.widget.RelativeLayout@2c72dfb0
  08-27 14:16:56.628: D/Checks(15025): listItem2: android.widget.RelativeLayout@2bfabe50
  08-27 14:16:56.638: D/Checks(15025): listItem1: android.widget.RelativeLayout@2c730c18
  08-27 14:16:56.638: D/Checks(15025): listItem2: android.widget.RelativeLayout@2c0d3e38
  08-27 14:16:56.638: D/Checks(15025): listItem1: android.widget.RelativeLayout@2c12ebc0
  08-27 14:16:56.638: D/Checks(15025): listItem2: android.widget.RelativeLayout@2bddbf70
  08-27 14:16:56.648: D/Checks(15025): listItem1: android.widget.RelativeLayout@2c131828
  08-27 14:16:56.648: D/Checks(15025): listItem2: android.widget.RelativeLayout@2bdf3270
  08-27 14:16:56.648: D/Checks(15025): listItem1: android.widget.RelativeLayout@2c140de0
  08-27 14:16:56.648: D/Checks(15025): listItem2: android.widget.RelativeLayout@2c0c8d30
  </code></pre>
  
  <p>listItem2 points to the actual View in the ListView, which is what I want except that it only works for Views that are in sight. You can see from the log file that listItem1 and listItem2 don't correspond.</p>
  
  <p><strong>EDIT 2:</strong></p>
  
  <p>I came up with the following:</p>
  
  <pre><code>for (int i = 0; i &lt; mListView.getCount(); i++) {
      RelativeLayout listItem = (RelativeLayout) mListView.getAdapter().getView(i, mListView.getChildAt(i), mListView);
  }
  </code></pre>
  
  <p>This returns the Views correctly for all visible items in the list. However, it returns a different View for the ones that aren't in sight.</p>
  
  <p><strong>EDIT 3:</strong></p>
  
  <p>Thanks to nfirex I have a working answer. This will return Views even if they're not directly in sight:</p>
  
  <pre><code>public View getViewByPosition(int position, ListView listView) {
      final int firstListItemPosition = listView.getFirstVisiblePosition();
      final int lastListItemPosition = firstListItemPosition + listView.getChildCount() - 1;
  
      if (position &lt; firstListItemPosition || position &gt; lastListItemPosition ) {
          return listView.getAdapter().getView(position, listView.getChildAt(position), listView);
      } else {
          final int childIndex = position - firstListItemPosition;
          return listView.getChildAt(childIndex);
      }
  }
  </code></pre>