1 package org.robolectric.shadows; 2 3 import android.view.View; 4 import android.widget.HeaderViewListAdapter; 5 import android.widget.ListView; 6 import java.util.ArrayList; 7 import java.util.List; 8 import org.robolectric.annotation.Implements; 9 import org.robolectric.annotation.RealObject; 10 11 @SuppressWarnings({"UnusedDeclaration"}) 12 @Implements(ListView.class) 13 public class ShadowListView extends ShadowAbsListView { 14 @RealObject private ListView realListView; 15 getHeaderViews()16 public List<View> getHeaderViews() { 17 HeaderViewListAdapter adapter = (HeaderViewListAdapter) realListView.getAdapter(); 18 ArrayList<View> headerViews = new ArrayList<>(); 19 int headersCount = adapter.getHeadersCount(); 20 for (int i = 0; i < headersCount; i++) { 21 headerViews.add(adapter.getView(i, null, realListView)); 22 } 23 return headerViews; 24 } 25 getFooterViews()26 public List<View> getFooterViews() { 27 HeaderViewListAdapter adapter = (HeaderViewListAdapter) realListView.getAdapter(); 28 ArrayList<View> footerViews = new ArrayList<>(); 29 int offset = adapter.getHeadersCount() + adapter.getCount() - adapter.getFootersCount(); 30 int itemCount = adapter.getCount(); 31 for (int i = offset; i < itemCount; i++) { 32 footerViews.add(adapter.getView(i, null, realListView)); 33 } 34 return footerViews; 35 } 36 } 37