Created
November 15, 2016 08:12
-
-
Save pantos27/811ca6de78ace666ab58d0188a578509 to your computer and use it in GitHub Desktop.
CircularArrayAdapter, never ending loop list view adapter
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//once created, set the position to the middle | |
listViewObject.setSelectionFromTop(nameOfAdapterObject.MIDDLE, 0); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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