Skip to content

Instantly share code, notes, and snippets.

@pantos27
Created November 15, 2016 08:12
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save pantos27/811ca6de78ace666ab58d0188a578509 to your computer and use it in GitHub Desktop.
Save pantos27/811ca6de78ace666ab58d0188a578509 to your computer and use it in GitHub Desktop.
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