My Android advanced tour ------ & gt; how to add a quick slider to the ListView component and modify the quick slider image, androidlistview

Source: Internet
Author: User

My Android advanced tour ------> how to add a quick slider to the ListView component and modify the quick slider image, androidlistview

To use the layout file, you need to set 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"        />
To use Java code, you must call the AbsListView. setFastScrollEnabled (boolean enabled) method. The following code is used:

     ListView listView=new ListView(getApplicationContext());     listView.setFastScrollEnabled(true);

The ListView component does not provide an API for modifying the quick slider image. Therefore, you cannot directly modify the quick slider image. However, you can use the reflection technology to modify the slider image. The Code is as follows:

// FastScroller. the mThumbDrawable variable saves the quick slider image // you must first use the AbsListView. mFastScroller gets the FastScroller object Field = AbsListView. class. getDeclaredField ("mFastScroller"); field. setAccessible (true); Object object = field. get (listView); // get FastScroller. field = field. getType (). getDeclaredField ("mThumbDrawable"); field. setAccessible (true); // get FastScroller. the value of the mThumbDrawable variable Drawable drawable = (Drawable) field. get (object); // load the new slider object drawable = getResources (). getDrawable (R. drawable. img); // reset the field of the slider object. set (object, drawable); // you can specify the minimum number of fields. setAccessible (true); Field minPages = object. getClass (). getDeclaredField ("MIN_PAGES"); minPages. setAccessible (true); minPages. set (object, 1 );

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

Author: Ouyang Peng: Welcome to repost. sharing with others is the source of progress!

Reprinted Please retain the original address: http://blog.csdn.net/ouyang_peng

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




Copyright Disclaimer: This article is an original article by the blogger and cannot be reproduced without the permission of the blogger.

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.