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

后端 未结 3 2135
心在旅途
心在旅途 2020-12-14 17:05

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 da

3条回答
  •  被撕碎了的回忆
    2020-12-14 17:44

    In reference to greg7gkb's comment above - just wanted to point out in case anyone is using this that it will make your count off by one. It should be

    (listView1.getLastVisiblePosition() - listView1.getFirstVisiblePosition()) + 1
    

    So, if the last visible was 8 and the first visible was 5, you would have (8-5)+1 = 4 showing:5,6,7, and 8.

    It looks like A. Abiri got it right below.

提交回复
热议问题