Skip to content

Instantly share code, notes, and snippets.

@evasyuk
Created June 29, 2015 17:35
Show Gist options
  • Save evasyuk/c5c4afb9bc5dfac7a155 to your computer and use it in GitHub Desktop.
Save evasyuk/c5c4afb9bc5dfac7a155 to your computer and use it in GitHub Desktop.
CircularArrayAdapter
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