Android Learning Series (15) -- cursor ListView of App list (index ListView)

Source: Internet
Author: User

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.

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.