Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
CircularArrayAdapter, never ending loop list view adapter
//once created, set the position to the middle
listViewObject.setSelectionFromTop(nameOfAdapterObject.MIDDLE, 0);
public class CircularArrayAdapter extends ArrayAdapter
{
public static final int HALF_MAX_VALUE = Integer.MAX_VALUE/2;
public final int MIDDLE;
private T[] objects;
public CircularArrayAdapter(Context context, int textViewResourceId, T[] objects)
{
super(context, textViewResourceId, objects);
this.objects = objects;
MIDDLE = HALF_MAX_VALUE - HALF_MAX_VALUE % objects.length;
}
@Override
public int getCount()
{
return Integer.MAX_VALUE;
}
@Override
public T getItem(int position)
{
return objects[position % objects.length];
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment