All Downloads are FREE. Search and download functionalities are using the official Maven repository.

org.robolectric.shadows.ShadowListView Maven / Gradle / Ivy

There is a newer version: 4.14.1
Show newest version
package org.robolectric.shadows;

import android.view.View;
import android.widget.HeaderViewListAdapter;
import android.widget.ListView;
import java.util.ArrayList;
import java.util.List;
import org.robolectric.annotation.Implements;
import org.robolectric.annotation.RealObject;

@SuppressWarnings({"UnusedDeclaration"})
@Implements(ListView.class)
public class ShadowListView extends ShadowAbsListView {
  @RealObject private ListView realListView;

  public List getHeaderViews() {
    HeaderViewListAdapter adapter = (HeaderViewListAdapter) realListView.getAdapter();
    ArrayList headerViews = new ArrayList<>();
    int headersCount = adapter.getHeadersCount();
    for (int i = 0; i < headersCount; i++) {
      headerViews.add(adapter.getView(i, null, realListView));
    }
    return headerViews;
  }

  public List getFooterViews() {
    HeaderViewListAdapter adapter = (HeaderViewListAdapter) realListView.getAdapter();
    ArrayList footerViews = new ArrayList<>();
    int offset = adapter.getHeadersCount() + adapter.getCount() - adapter.getFootersCount();
    int itemCount = adapter.getCount();
    for (int i = offset; i < itemCount; i++) {
      footerViews.add(adapter.getView(i, null, realListView));
    }
    return footerViews;
  }
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy