Problems with adding headers with Pulltorefreshlistview in the Android-pulltorefresh library

Source: Internet
Author: User

In development we often have the need to add headers to the ListView, and this ListView also provides a pull-down refresh feature. Drop-down Refresh library Android-pulltorefresh is a nice drop-down refresh library that supports not only the ListView, but also the Gridview,webview,scrollview. But I didn't find the Addheaderview method when I wanted to add a header to Pulltorefreshlistviews. Later found that Pulltorefreshlistviews is not a sub-class of the ListView. He holds a ListView object inside. So I found the code below to add a header.

        MINVITERECORDLV = (Pulltorefreshlistview) Findviewbyid (r.id.invest_record_list);        View Header = Getlayoutinflater (). Inflate (R.layout.invite_record_header, MINVITERECORDLV, false);        ListView LV = Minviterecordlv.getrefreshableview ();        Lv.addheaderview (header);        Minviterecordlv.setadapter (New Inviterecordadapter (this));


I thought it would be fine to write like that, but when I ran the program, I got the following error:

Java.lang.classcastexception:android.widget.linearlayout$layoutparams cannot is cast to Android.widget.abslistview$layoutparams

And then I changed the code to the bottom so I could get the result.

        MINVITERECORDLV = (Pulltorefreshlistview) Findviewbyid (r.id.invest_record_list);        Abslistview.layoutparams layoutparams = new Abslistview.layoutparams (AbsListView.LayoutParams.MATCH_PARENT, AbsListView.LayoutParams.WRAP_CONTENT);        View Header = Getlayoutinflater (). Inflate (R.layout.invite_record_header, MINVITERECORDLV, false);        Header.setlayoutparams (layoutparams);        ListView LV = Minviterecordlv.getrefreshableview ();        Lv.addheaderview (header);        Minviterecordlv.setadapter (New Inviterecordadapter (this));


Android-pulltorefresh Library: Https://github.com/chrisbanes/Android-PullToRefresh


Problems with adding headers with Pulltorefreshlistview in the Android-pulltorefresh library

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.