RecyclerView上拉加载更多下拉刷新优雅姿势

BaseRecyclerViewAdapterHelper+EasyRefreshLayout优雅实现recyclerView上拉加载更多下拉刷新
直接上代码:
布局:
<com.ajguan.library.EasyRefreshLayout
  android:id="@+id/easylayout"
  android:layout_width="match_parent"
  android:layout_height="match_parent">

  <android.support.v7.widget.RecyclerView
    android:id="@+id/recyclerList"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:background="@color/transparent">

  </android.support.v7.widget.RecyclerView>
</com.ajguan.library.EasyRefreshLayout>
配置代码:
mManager = new GridLayoutManager(this.getContext(), 6);
    easyRefreshLayout.setRefreshHeadView(new RefreshHeaderView(getActivity()));
    mRecyclerList.setLayoutManager(mManager);
//设置adapter
    productAdapter = new ProductAdapter(this.getContext(), R.layout.item_product, new ArrayList());
    productAdapter.openLoadAnimation();
    mRecyclerList.setHasFixedSize(true);
    mRecyclerList.setAdapter(productAdapter);

监听事件:
productAdapter.setOnItemClickListener(new BaseQuickAdapter.OnItemClickListener() {
  @Override
  public void onItemClick(BaseQuickAdapter adapter, View view, int position) {
    MyUtil.outLog("item" + position);
  }
});
easyRefreshLayout.addEasyEvent(new EasyRefreshLayout.EasyEvent() {
  @Override
  public void onLoadMore() {
}

@Override
public void onRefreshing() {
}})
适配器:
public class ProductAdapter extends BaseQuickAdapter<ResultBean, BaseViewHolder> {
  private Context context;

  public ProductAdapter(Context context, int layoutResId, List data) {
    super(layoutResId, data);
    this.context = context;
  }

  @Override
  protected void convert(BaseViewHolder helper, ResultBean item) {
    helper.setText(R.id.tv_product_price, "¥" + item.getOfferPrice());
//    helper.setImageResource(R.id.icon,R.mipmap.icon_price_background );
//状态处理注意helper复用问题    Glide.with(context).load(item.getImageUrl()).diskCacheStrategy(DiskCacheStrategy.ALL).override(200, 500)
      .fitCenter().into((ImageView) helper.getView(R.id.iv_product_pic));
  }
}
具体使用请参考官方文档:
compile 'com.github.CymChad:BaseRecyclerViewAdapterHelper:2.9.34'//是一个强大的RecyclerAdapter框架优点不多说:https://www.jianshu.com/p/b343fcff51b0
compile 'com.github.anzaizai:EasyRefreshLayout:1.3.1'//这是一个独立的上拉加载下拉刷新库
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值