1 package org.robolectric.shadows; 2 3 import android.view.View; 4 import android.view.ViewGroup; 5 import android.widget.BaseAdapter; 6 import android.widget.TextView; 7 import androidx.test.core.app.ApplicationProvider; 8 9 class ShadowCountingAdapter extends BaseAdapter { 10 private int itemCount; 11 ShadowCountingAdapter(int itemCount)12 public ShadowCountingAdapter(int itemCount) { 13 this.itemCount = itemCount; 14 } 15 setCount(int itemCount)16 public void setCount(int itemCount) { 17 this.itemCount = itemCount; 18 notifyDataSetChanged(); 19 } 20 21 @Override getCount()22 public int getCount() { 23 return itemCount; 24 } 25 26 @Override getItem(int position)27 public Object getItem(int position) { 28 return null; 29 } 30 31 @Override getItemId(int position)32 public long getItemId(int position) { 33 return 0; 34 } 35 36 @Override getView(int position, View convertView, ViewGroup parent)37 public View getView(int position, View convertView, ViewGroup parent) { 38 TextView textView = new TextView(ApplicationProvider.getApplicationContext()); 39 textView.setText("Item " + position); 40 return textView; 41 } 42 } 43