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