My colleague is Joe, and I believe that we have found an easier way to solve the same problem. In our solution, instead of extending the BaseAdapter, we extend the ArrayAdapter.
The code is as follows:
public class CircularArrayAdapter< T > extends ArrayAdapter< T > { 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]; } }
Thus, a class is created called CircularArrayAdapter, which takes the type of the object T (which can be any) and uses it to create a list of arrays. T is usually a string, although it can be anything.
The constructor is the same as for the ArrayAdapter, but it initializes a constant named middle. This is the middle of the list. No matter how long the MIDDLE array can be used to center the ListView in the middle of the list.
getCount() overrides to return a huge value, as was done above when creating a huge list.
getItem() overrides to return a fake position in the array. Thus, when filling out the list, the list is filled with objects cyclically.
At this point, the CircularArrayAdapter simply replaces the ArrayAdapter in the file that creates the ListView.
To center the ListView, the following line must be inserted into your file, creating the ListView after the ListView object is initialized:
listViewObject.setSelectionFromTop(nameOfAdapterObject.MIDDLE, 0);
and using the MIDDLE constant pre-initialized for the list, the view is centered with the top of the list at the top of the screen.
:) ~ Cheers, I hope this solution is useful.