Git Product home page Git Product logo

hvendlessrecyclerview's Introduction

HVEndlessRecyclerView

该项目是学习如何封装 loadmore 功能时候的实验作品,未投入生产环境测试,如有需要,请移步至 PullRecycler

Easy way implements loadmore

Thanks Cube-Sdk,秋哥的 loadmore 模块真的写得很好!

1.Click 事件支持

    // 支持 Click 事件
    mSampleAdapter.setOnItemClickListener(new OnRcvItemClickListener() {
      @Override public void onItemClick(View v, int position) {
        Toast.makeText(MainActivity.this, "点击事件支持,item position -->>" + position,
            Toast.LENGTH_SHORT).show();
      }
    });
    // 支持 LongClick 事件
    mSampleAdapter.setOnItemLongClickListener(new OnRcvItemLongClickListener() {
      @Override public boolean onItemLongClick(View view, int position) {
        Toast.makeText(MainActivity.this, "长按点击事件支持,item position -->>" + position,
            Toast.LENGTH_SHORT).show();
        return true;
      }
    });

2. 使用默认的 footer

    mRecyclerView.setAdapter(mSampleAdapter);
    mRecyclerView.useDefaultFooter(); // 请在 setAdapter 之后设置默认的 footer

3.加载更多数据

    mRecyclerView.setLoadMoreHandler(new ILoadMoreHandler() {
          @Override public void onLoadMore() {
            simulateLoadMoreData();
        }
      });

4. 加载完成之后,设置状态

  • 内容是否为空

  • 是否有更多数据

/**
   * 
   * @param isEmpty fetch 的数据列表是否为空
   * @param hasMore 是否还有更多数据
   */
  @Override public void onLoadMoreCompleted(boolean isEmpty, boolean hasMore) {
  
  }

5.加载失败

/**
   * 
   * @param errorCode 错误码
   * @param errorMsg 错误信息
   */
  @Override public void onLoadMoreFailed(int errorCode, String errorMsg) {
  
  }

嫌弃我写的 Footer 不好看,你可以自定义 Footer !

/**
 *
 * 对 LoadMoreView 的抽象
 */
public interface ILoadMoreUIHandler {

  // 加载中
  void onLoading();
  // 加载完毕
  void onLoadFinish(boolean isEmpty, boolean hasMore);
  // 加载出错
  void onLoadError(int errorCode, String errorMsg);
  // 等待被点击加载更多
  void onWaitToLoadMore();
}

Tips

具体可以参考 DefaultLoadMoreFooterView 这个栗子

最后,来自笔者的善意,nice footer and header

1.当 LayoutManager 为 LinearLayoutManager

2.当 LayoutManager 为 GridLayoutManager

3.当 LayoutManager 为 StaggeredGridLayoutManager

// 请自行想象...

hvendlessrecyclerview's People

Contributors

hellovass avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.