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

后端 未结 3 2107
心在旅途
心在旅途 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:47

    listView.getLastVisiblePosition(), is this what you are looking for? if not, Iteration through child views...

    int count = 0;
    
    for (int i = 0; i <= listView.getLastVisiblePosition(); i++)
    {
        if (listView.getChildAt(i) != null)
        {
            count++;  // saying that view that counts is the one that is not null, 
                      // because sometimes you have partially visible items....
        }
    }
    

提交回复
热议问题