2013-11-22 28 views

回答

7

我的实现在更新两个库之后也被破坏了。这是我的快速修复程序,使其再次工作。 欢迎任何建议和改进!

  1. 创建一个新的类,并延长SticklistListHeadersListView并实现从动作条,PullToRefresh的ViewDelegate接口:

    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. 而在你layout.xml更换

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

    <com.yourapp.package.foo.PtrStickyListHeadersListView 
         ...> 
    
  3. ,最后,添加代理:listView是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); 
    
+0

它工作的很好,谢谢 – Ray

3

到赫尔登的回答一样,你也可以做到这一点使用匿名内部类不延长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); 
相关问题