首页

源码搜藏网

首页 > 安卓源码 > 控件分类 > 列表ListView >

用于在RecyclerView和AbsListView上创建简单分页功能的库

创建时间:2017-01-22 09:56  

用于在RecyclerView和AbsListView上创建简单分页功能的库
用于在RecyclerView和AbsListView上创建简单分页功能的库
暂无演示 立即下载

Android的库,用于在创建简单的分页功能(又名无限滚动)RecyclerView或 AbsListView

特征

演示

对于这个项目的执行工作看到了paginate-sample/文件夹。

建立

Gradle:


	
compile 'com.github.markomilos:paginate:0.5.1'

或Maven:


	
<dependency>
  <groupId>com.github.markomilos</groupId>
  <artifactId>paginate</artifactId>
  <version>0.5.1</version>
</dependency>

用法

实行 Paginate.Callbacks


	
Paginate.Callbacks callbacks = new Paginate.Callbacks() {
    @Override
    public void onLoadMore() {
        // Load next page of data (e.g. network or database)
    }

    @Override
    public boolean isLoading() {
        // Indicate whether new page loading is in progress or not
        return loadingInProgress;
    }

    @Override
    public boolean hasLoadedAllItems() {
        // Indicate whether all data (pages) are loaded or not
        return hasLoadedAllItems;
    }
};

RecyclerView


	
Paginate.with(recyclerView, callbacks)
        .setLoadingTriggerThreshold(2)
        .addLoadingListItem(true)
        .setLoadingListItemCreator(new CustomLoadingListItemCreator())
        .setLoadingListItemSpanSizeLookup(new CustomLoadingListItemSpanLookup())
        .build();

LayoutManagerRecyclerView.Adapter需要调用上述代码之前进行设置。

实现LoadingListItemCreator以提供自定义加载行视图。


	
private class CustomLoadingListItemCreator implements LoadingListItemCreator {
    @Override
    public RecyclerView.ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
        LayoutInflater inflater = LayoutInflater.from(parent.getContext());
        View view = inflater.inflate(R.layout.custom_loading_list_item, parent, false);
        return new VH(view);
    }

    @Override
    public void onBindViewHolder(RecyclerView.ViewHolder holder, int position) {
        // Bind custom loading row if needed
    }
}

AbsListView


	
Paginate.with(absListView, callbacks)
        .setOnScrollListener(scrollListener) // Delegate scroll listener
        .setLoadingTriggerThreshold(2)
        .addLoadingListItem(true)
        .setLoadingListItemCreator(new CustomLoadingListItemCreator())
        .build();

:适配器需要调用上述代码之前进行设置。

实现LoadingListItemCreator以提供自定义加载行视图。


	
private class CustomLoadingListItemCreator implements LoadingListItemCreator {
    @Override
    public View newView(int position, ViewGroup parent) {
        LayoutInflater inflater = LayoutInflater.from(parent.getContext());
        View view = inflater.inflate(R.layout.custom_loading_list_item, parent, false);
        view.setTag(new VH(view));
        return view;
    }

    @Override
    public void bindView(int position, View view) {
        // Bind custom loading row if needed
    }
}

分页实例

调用build()Paginate.Builder将返回Paginate的实例,这将使您:

上一篇:TwinklingRefreshLayout 小而强大的刷新控件,自带顺滑的越界回
下一篇:一个下拉刷新上拉加载更多的Android框架

相关内容

热门推荐