Android Development-drop-down refresh and segmented header hover list

Source: Internet
Author: User

Project Source

The project described herein is open source, source address

Why do Pulltorefresh-pinnedsection-listview

The previous time because of the project needs, the need to add a drop-down refresh and segmented head hover effect on the ListView in Android, inspired by Dkmeteor, merges two open source projects on GitHub:

    • Android-pulltorefresh (Handmark version, currently no longer updated)

    • Stickylistheaders (current version is 2.x)

      As the existing project Stickylistheaders code for the 1.x version, Stickylistheaderslistview inherit from the ListView, so with the Handmark version of Pulltorefreshlistview do the merge is smooth;

      However, the 2.x version of Stickylistheaderslistview inherited from the Framelayout, and Pulltorefresh fusion is not smooth, to sort out a separate Lib encountered a lot of problems, so in the split-off hover demand on the use of another similar open source project:

    • Pinned-section-listview

How I did it.

The process described earlier is "very smooth":

1.Library, based on the Pulltorefresh Library modification, first make it dependent on the Stickylistheaders library, by copying src/com/handmark/pulltorefresh/ Library/pulltorefreshlistview.java class, New Pulltorefreshpinnedsectionlistview.java class;

2. Modify the Createlistview () method in the Pulltorefreshpinnedsectionlistview class, commenting the following code

[Java]View Plaincopyprint?
    1. if (VERSION. Sdk_int >= version_codes. Gingerbread) {
    2. LV = new InternalListViewSDK9 (context, attrs);
    3. } else {
    4. LV = new Internallistview (context, attrs);
    5. //        }

Add to

[Java]View Plaincopyprint?
    1. LV = New Pinnedsectionlistview (context, attrs);

3.Example, based on the Pinned-section-listview example modification, making it dependent on the Pulltorefresh library;

4. Modify the main class resource file Activity_main.xml, set the list component to the new class:

[HTML]View Plaincopyprint?
  1. <com.handmark.pulltorefresh.library.PullToRefreshPinnedSectionListView xmlns:android="/http Schemas.android.com/apk/res/android "
  2. android:id="@+id/list"
  3. Android:layout_width="Match_parent"
  4. android:layout_height="Wrap_content"
  5. android:headerdividersenabled="false"
  6. android:footerdividersenabled="false"
  7. android:divider="@null"
  8. />

5. Rewrite the Getlistview () method in the Sampleactivity.java class:

[Java]View Plaincopyprint?
    1. Mppulltorefreshpinnedsectionlistview = (Pulltorefreshpinnedsectionlistview) Findviewbyid (R.id.list);
    2. return Mppulltorefreshpinnedsectionlistview.getrefreshableview ();

You can pass

[Java]View Plaincopyprint?
    1. ListView list = Getlistview ();

Continue with the original example other operations, details can read the project code

Another way to implement

The implementation of this example relies on the flexibility of the Handmark version of the drop-down refresh component, more importantly, requires that the segmented head hover component is inherited from the ListView implementation, so the same can be used Handmark version of the drop-down refresh components and 1.x version of the Stickylistheaders component implementation;

Another way to achieve this is pull-to-refresh-sticky-list, Its merger is the 2.x version of the stickylistheaders and Johannilsson Android-pulltorefresh, the implementation of different forms, but similar effects, read the code after the implementation is also "quite smooth", interested students can refer to this project;

Suggestions

It is recommended to use this class library if you are familiar with or have used the original Component class library.

Android Development-drop-down refresh and segmented header hover list

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.