Is it possible to combine stickylistviewheader with crisbanes pulltorefresh?

I am creating an application where pulltorefresh and stickylistHeaders are needed too. I implemented pulltorefresh in the application, but I can not get it to work with stickyListHeaders. Can two libraries be combined? Or is there an alternative? Any ideas?

+4
source share
2 answers

My implementation was interrupted after updating both libraries. This is my quick fix.so that it works again. Any suggestions or improvements are welcome!

  • Create 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;
        }
    }
    
  • layout.xml

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

    <com.yourapp.package.foo.PtrStickyListHeadersListView
            ...>
    
  • , , : (listView - PtrStickyListHeadersListView)

    ActionBarPullToRefresh.from(getActivity())
            // We need to insert the PullToRefreshLayout into the Fragment  ViewGroup
            .insertLayoutInto(viewGroup)
            // We need to mark the ListView and it  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);
    
+7

Helden, , , 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);
+3

All Articles