My Android Step-by-step tour------> How to add a fast speed slider to a ListView component and modify the speed slider image

Source: Internet
Author: User

Using a layout file requires the android:fastscrollenabled= "true", as shown in the following code:

    <listview         android:id= "@+id/listview" android:layout_width= "fill_parent" android:layout_height= "Fill_     Parent "android:fastscrollenabled=" true "     android:focusable=" true "        />
Using Java code requires calling the Abslistview. setfastscrollenabled (Boolean enabled) method. As shown in the following code:

     ListView listview=new ListView (Getapplicationcontext ());     Listview.setfastscrollenabled (TRUE);

The ListView component does not provide an API to modify the speed slider image, so you cannot modify the speed slider image directly. However, the fast speed slider image can be modified by reflection technology, as follows:

                    Fastscroller.mthumbdrawable variable saves a quick slider image    //First to get Fastscroller object by abslistview.mfastscroller    Field field = AbsListView.class.getDeclaredField ("Mfastscroller");     Field.setaccessible (true);     Object Object=field.get (listView);     Gets the object of the fastscroller.mthumbdrawable variable    field=field.gettype (). Getdeclaredfield ("mthumbdrawable");     Field.setaccessible (true);     Gets the value of the fastscroller.mthumbdrawable variable    drawable drawable= (drawable) Field.get (object);     Loads a new Quick slider object    drawable=getresources (). getdrawable (r.drawable.img);     Reset the speed skating block object    Field.set (object,drawable);                    Set the minimum number of pages    field. Setaccessible (true);    Field minpages =object.getclass (). Getdeclaredfield ("Min_pages");    Minpages.setaccessible (TRUE);    

==================================================================================================

Ouyangpeng welcome reprint, sharing with people is the source of progress!

Reprint please keep the original address : Http://blog.csdn.net/ouyang_peng

==================================================================================================

  


Copyright NOTICE: This article for Bo Master original article, without Bo Master permission not reproduced.

My Android Step-by-step tour------> How to add a fast speed slider to a ListView component and modify the speed slider image

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.