preface

RecyclerView is our basic will be used in the development of a control, RecyclerView adapter needs to write by ourselves, if you don’t wrap a fully functional, and don’t want to use BaseRecyclerViewAdapterHelper library, the size of Try RainBaseAdapter, a lightweight, simple and versatile RecyclerView adapter

Begin to use

RainBaseAdapter is a versatile RecyclerView adapter. It is lightweight and supports adding headers, tails, empty views and pull-up loading and much more

Introducing way

compile 'com. Rain: RainBaseAdapter: 1.1.0'
Copy the code

Follow the trend, based on AndroidX development, please ensure that the code has been upgraded to AndroidX before using

Creating an adapter

Very convenient to use, clean and hygienic

class MainAdapter(activity: Activity, list: MutableList<String>) : RainBaseRvAdapter<String>(Activity, list) {override Fun convertData(holder: RainBaseRvViewHolder? , entity: String? , position: Int) { holder? .getTextView(R.id.vTvContent)? .text = entity} /** * Override Fun getLayoutViewId(viewType: Int): Int {return R.layout.adapter_main
    }

}
Copy the code

Add HeadView

Public void addHeaderView(view view, Boolean isNotify) {} public void addHeaderView(view view, Boolean isNotify) {}Copy the code

Add FootView

Public void addFootView(view view, Boolean isNotify) {} public void addFootView(view view, Boolean isNotify) {}Copy the code
EmptyView does not open an EmptyView by default. If EmptyView is set and the list data source is empty, the EmptyView will be displayedsetEmptyView(View View) {} /** * @param openEmptyView whether to enable EmptyView(default to disable EmptyView) */ public voidsetOpenEmptyView(boolean openEmptyView)
Copy the code

Set up pull-up loading for more

RainBaseAdapter provides pull-up loading of more views by default and can be customized

/** * @param View */ public voidsetLoadMoreView(View View) {} /** * pull load listener ** @param iLoadMoreListener */ public voidsetAdapterLoadMoreListener (RainAdapterLoadMoreListener iLoadMoreListener) {} / * * * to open the tensile loading not updated adapter * / public voidstartLoadMore() {} /** * closes pull-up loading of unupdated adapters */ public voidendLoadMore() {} /** * display loadmoReview error, but turn off listener */ public voiderrorLoadMore() {} /** * LoadMoReview is displayed, but listener is closed */ public voidfinishLoadMoreView Listener ** @param mLoadMoreResultListener */ public voidsetLoadMoreResultListener(RainAdapterLoadMoreClickListener mLoadMoreResultListener) {}
Copy the code

Event listeners

/** * item click listener ** @param iOnClickListener */ public voidsetAdapterItemOnClickListener (RainAdapterItemOnClickListener iOnClickListener) {} / item long by listening to * * * * * @ param iOnLongClickListener */ public void setiOnLongClickListener(RainAdapterItemLongClickListener iOnLongClickListener) {} /** * @param iOnChildClickListener * @param listenerId */ public voidsetNeedListenerChildId(RainAdapterChildItemOnClickListener iOnChildClickListener, Int [] listenerId) {} / * * * set up dynamic monitor child View * * @ param iOnChildClickListener child View click listen * @ param iOnChildLongClickListener * @param listenerId Id of a subview */ public voidsetNeedListenerChildId(RainAdapterChildItemOnClickListener iOnChildClickListener
            , RainAdapterChildItemLongClickListener iOnChildLongClickListener, int[] listenerId) {}
Copy the code

Remove HeadView and FootView and update data

** @position */ public void removeHeaderView(int position, Public void removeFootView(int position, int position) Boolean isNotify {} public void removeFootView(int position, int position, int position) Boolean isNotify {} /** * Delete all headViews */ public voidremoveAllHeadView() {} /** * delete all FootView */ public voidremoveAllFootViewPublic void upData(list <T> list) {} public void upData(list <T> list) {} @param list */ public void addData(List<T> list) {}Copy the code

A long way to go

This adapter basically contains the functions we need to use in daily use, simple, light and fast, welcome your comments and suggestions, you can collect some need to supplement the function points to join in the future, the road is long, we work together ~

Put the code over RainBaseAdapter

If you like this adapter, welcome Star~ thanks ~~