Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Android: Getting a count of the visible children in a listview

Tags:

Is there are way to get a count of the number of visible listview children?

I have a listview with info linked to a database that can change at any time. When the database is changed, I send out a broadcast notifying the ui class handling the list view. The child element relating to the changed data is then updated. I am achieving this by giving each listview item a tag, and then iterating over the listviews to find the row matching the tag from the broadcast.

I want to only iterate over the visible children. There is no need for me to manually update views that are not visible, as they will reflect the new data when they are created. I currently iterate from listView.getfirstVisiblePosition() to listView.getChildCount(). This is better than nothing, as I don't examine rows above the visible rows, but I don't want to examine the rows below them either.

I checked the android developers listView page and didn't find anything. Anyone know of a way I can get the count of visible children?

Thanks!

like image 865
Chris Avatar asked Jul 18 '11 22:07

Chris


1 Answers

This is a quick way to get visible children count:

int visibleChildCount = (listView1.getLastVisiblePosition() - listView1.getFirstVisiblePosition()) + 1; 
like image 80
A. Abiri Avatar answered Oct 29 '22 09:10

A. Abiri