Even if we have enabled fast scroll, it is still difficult to know where we are in the list. To get around this, we make use of section indexes.
Making a list show a section index popup while scrolling is quite easy, requiring only that the adapter implements the ISectionIndexer
interface. Let's take a look at the following steps:
In order to enable the section index, we need to ensure that fast scroll is enabled on the list view:
listView.FastScrollEnabled = true;
Then we ensure that the list adapter implements the
ISectionIndexer
interface:public class PeopleAdapter : BaseAdapter<Person>, ISectionIndexer { public int GetPositionForSection(int section) { } public int GetSectionForPosition(int position) { } public Java.Lang.Object[] GetSections() { } }
We can calculate all of these values on-the fly but, for performance reasons, we do some of it in the constructor. Here, we group the data by the first letter of the name:
private readonly...