Get all ListView items(rows)

前端 未结 4 1183
孤街浪徒
孤街浪徒 2020-12-17 22:53

How may I get all children of an item of ListView ?
There are methods to get child at position but I was not able to find any method which returns collectio

4条回答
  •  臣服心动
    2020-12-17 23:26

    Use this method to get all insight and out-sight view of list view:

    for ( int i = 0 ; i < listView.getCount() ; i++){
        View v = getViewByPosition(i,listView);
    }
    
    public View getViewByPosition(int position, ListView listView) {
        final int firstListItemPosition = listView.getFirstVisiblePosition();
        final int lastListItemPosition =firstListItemPosition + listView.getChildCount() - 1;
    
        if (position < firstListItemPosition || position > lastListItemPosition ) {
            return listView.getAdapter().getView(position, listView.getChildAt(position), listView);
        } else {
            final int childIndex = position - firstListItemPosition;
            return listView.getChildAt(childIndex);
        }
    }
    

提交回复
热议问题