ListView getChildAt returning null for visible children

listView.getChildAt(i) works where 0 is the very first visible row and (n-1) is the last visible row (where n is the number of visible views you see).

The get last/first visible return the position in the dataAdapter you have. So you since you start at position 3, with what looks like 6 visible views, that’s when get for positions 6-8 you get null.

In your example getChildAt(0) would return position 3. What I usually do is store the position on my views so I can lookup on my dataAdapter later if I need values.

I think your for loop should look like this:

for (int i = 0; i <= f_listView.getLastVisiblePosition() - f_listView.getFirstVisiblePosition(); i++) 

Hope this helps.

Leave a Comment