Skip to content

🔥🔥🔥 - 用包装器模式给RecyclerView添加可以加载更多的Adapter

Notifications You must be signed in to change notification settings

simplepeng/LoadMoreAdapter

Repository files navigation

LoadMoreAdapter

用包装器模式给RecyclerView添加可以加载更多的Adapter

LinearLayoutManager GridLayoutManager StaggeredGridLayoutManager

导入依赖

allprojects {
	repositories {
		...
		maven { url 'https://jitpack.io' }
	}
}
dependencies {
        implementation 'com.github.simplepeng:LoadMoreAdapter:v1.0.5'
}

使用

loadMoreAdapter = LoadMoreAdapter.wrap(mAdapter)
loadMoreAdapter?.setOnLoadMoreListener {
    loadMoreData()
}
loadMoreAdapter?.setOnFailedClickListener { adapter, view ->
                                           
}
rv.adapter = loadMoreAdapter

自定义底部

class CustomFooter : ILoadMoreFooter {

    private var mTextView: TextView? = null

    override fun setLayoutRes(): Int {
        return R.layout.footer_custom
    }

    override fun onCreate(footerView: View) {
        mTextView = footerView.findViewById(R.id.tv_custom)
    }

    override fun loading(footerView: View) {
        mTextView!!.text = "加载更多中..."
    }

    override fun noMoreData(footerView: View) {
        mTextView!!.text = "我是有底线的"
    }

    override fun loadFailed(footerView: View) {
        mTextView!!.text = "服务器开了小差"
    }
}
loadMoreAdapter = LoadMoreAdapter.wrap(mAdapter, new CustomFooter());
rv.setAdapter(loadMoreAdapter);

可用方法

//加载失败
loadMoreAdapter.loadMoreFailed();
//已无更多数据
loadMoreAdapter.noMoreData();
//重置状态
loadMoreAdapter.resetNoMoreData();

版本迭代

  • v1.0.5:泛型适配原生的Adapter
  • v1.0.4:修复一直loading的bug
  • v1.0.3:升级AndroidXKotlin,修复bug
  • v1.0.2:迁移到jitpack
  • v1.0.0:首次上传

About

🔥🔥🔥 - 用包装器模式给RecyclerView添加可以加载更多的Adapter

Resources

Stars

Watchers

Forks

Packages

No packages published