is it possible to merge stickylistviewheader with crisbanes pulltorefresh?

ぃ、小莉子 提交于 2019-12-21 17:39:12

问题


I building an app where pulltorefresh and stickylistHeaders are both need.i have implemented the pulltorefresh in the app but am not able to make it work with stickyListHeaders.Is it possible to merge the two libraries? Or is there any alternative?any Ideas?


回答1:


My implementation was broken after updating both libraries, too. This is my quick fix to make it work again. Any suggestions and improvements are welcome!

  1. Make a new class and extend the SticklistListHeadersListView and implement the ViewDelegate interface from ActionBar-PullToRefresh:

    public class PtrStickyListHeadersListView extends StickyListHeadersListView
            implements ViewDelegate {
    
        public PtrStickyListHeadersListView(Context context) {
            super(context);
        }
    
        public PtrStickyListHeadersListView(Context context, AttributeSet attrs) {
            super(context, attrs);
        }
    
        public PtrStickyListHeadersListView(Context context, AttributeSet attrs, int defStyle) {
            super(context, attrs, defStyle);
        }
    
        @Override
        public boolean isReadyForPull(View view, float v, float v2) {
            View childView = getWrappedList().getChildAt(0);
            int top = (childView == null) ? 0 : childView.getTop();
            return top >= 0;
        }
    }
    
  2. And in your layout.xml replace

    <se.emilsjolander.stickylistheaders.StickyListHeadersListView
            ...>
    

    with

    <com.yourapp.package.foo.PtrStickyListHeadersListView
            ...>
    
  3. And at last, add the delegate: (listView is an instance of PtrStickyListHeadersListView)

    ActionBarPullToRefresh.from(getActivity())
            // We need to insert the PullToRefreshLayout into the Fragment 's ViewGroup
            .insertLayoutInto(viewGroup)
            // We need to mark the ListView and it 's Empty View as pullable
            // This is because they are not dirent children of the ViewGroup
            .theseChildrenArePullable(R.id.your_list_id)
            // We can now complete the setup as desired
            .listener(...)
            .useViewDelegate(PtrStickyListHeadersListView.class, listView)
            .setup(mPullToRefreshLayout);
    



回答2:


Similar to Helden's answer, you can also achieve this using an anonymous inner class without extending StickyListHeadersListView

    myList = (StickyListHeadersListView) v.findViewById(R.id.your_list_id);
    ActionBarPullToRefresh.from(getActivity())
            .allChildrenArePullable()
            .listener(this)
            .useViewDelegate(StickyListHeadersListView.class, new ViewDelegate() {
                @Override
                public boolean isReadyForPull(View view, float v, float v2) {
                    return ... //check if list is scrolled to the top or not
                }
            })
            .setup(mPullToRefreshLayout);


来源:https://stackoverflow.com/questions/20143008/is-it-possible-to-merge-stickylistviewheader-with-crisbanes-pulltorefresh

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!