SectionIndexer.java revision 5add56ec49cef52db7ebd3006665f318a5d16dd3
1/* 2 * Copyright (C) 2008 The Android Open Source Project 3 * 4 * Licensed under the Apache License, Version 2.0 (the "License"); 5 * you may not use this file except in compliance with the License. 6 * You may obtain a copy of the License at 7 * 8 * http://www.apache.org/licenses/LICENSE-2.0 9 * 10 * Unless required by applicable law or agreed to in writing, software 11 * distributed under the License is distributed on an "AS IS" BASIS, 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 * See the License for the specific language governing permissions and 14 * limitations under the License. 15 */ 16 17package android.widget; 18 19/** 20 * Interface that should be implemented on Adapters to enable fast scrolling 21 * in an {@link AbsListView} between sections of the list. A section is a group of list items 22 * to jump to that have something in common. For example, they may begin with the 23 * same letter or they may be songs from the same artist. ExpandableListAdapters that 24 * consider groups and sections as synonymous should account for collapsed groups and return 25 * an appropriate section/position. 26 */ 27public interface SectionIndexer { 28 /** 29 * This provides the list view with an array of section objects. In the simplest 30 * case these are Strings, each containing one letter of the alphabet. 31 * They could be more complex objects that indicate the grouping for the adapter's 32 * consumption. The list view will call toString() on the objects to get the 33 * preview letter to display while scrolling. 34 * @return the array of objects that indicate the different sections of the list. 35 */ 36 Object[] getSections(); 37 38 /** 39 * Provides the starting index in the list for a given section. 40 * @param section the index of the section to jump to. 41 * @return the starting position of that section. If the section is out of bounds, the 42 * position must be clipped to fall within the size of the list. 43 */ 44 int getPositionForSection(int section); 45 46 /** 47 * This is a reverse mapping to fetch the section index for a given position 48 * in the list. 49 * @param position the position for which to return the section 50 * @return the section index. If the position is out of bounds, the section index 51 * must be clipped to fall within the size of the section array. 52 */ 53 int getSectionForPosition(int position); 54} 55