The cursor ListView provides index tags so that you can quickly locate list items.
It can also be called index ListView. Some people call it Tweaked ListView, which may be more vivid.
I understand everything in the figure: <ignore_js_op> 1. cursor (Fast scroll thumb)
It is the drag block on the right, which is very simple:Copy code
It can also be written in the java Background:
Copy code
When the data volume is large, the so-called "cursor" on the right will appear in the sliding list.
Simple, which is why I like to write controls myself in private, but I like to use general controls at work.
Let's take a look at the source code, which is actually to enable the FastScroller object:
Copy code
2. letter Index
In the Android Learning Series (10)-App list drag-and-drop ListView (top), we use WindowManager to add some custom images to the ListView, I think this method is feasible.
However, the android system provides us with a simpler method: Use AlphabetIndexer.
AlphabetIndexer, which implements the SectionIndexer interface, is an auxiliary class of adapter. It helps to display index letters during fast slide.
If you use a letter index, you must ensure that the data list is sorted alphabetically so that AlphabetIndexerh can be quickly located using the binary search method.
Copy code
Three methods are used:
Copy code
3. Implementation of Cursor
The Cursor interface has two options:
(1) directly use the cursor returned by the database query
(2) define a new class to implement the Cursor Interface
The first method is simple. query the database and return the Cursor.
Here we use the second method to disguise a Cursor and implement three methods:
(1). getCount ()
(2). moveToPosition ()
(3). getString ()
Copy codeThe instance of this class can be used as the first parameter data cursor of the AlphaIndexer constructor. 4. Implementation of custom Adapter
Using the content described above, we can implement the final IndexAdapter:
Copy code
5. Run
The sample data is as follows:
Copy code
Layout file of the sub-item:
Copy code
Use and run:
Copy codeThe result is as follows: <ignore_js_op>
This indexing effect is very useful in the display of large data volumes and is essential for Android development.
This article is just a simple sample, and the actual work will definitely need to be further extended:
(3) For complex interface display, you can rewrite the getView method of the adapter to customize the view.