preview at google play:https://play.google.com/store/apps/details?id=com.freedom.yefeng.yfrecyclerview.example
a powerful list recycler view to replace list view, with function belows:
1.header and footer view
2.auto load more
3.pull to refresh
4.list divider
5.change display mode (data,empty,error)
6.add recycler view inside recycler view demo
include libs in your build.gradle
or see it in maven :https://bintray.com/yefengfreedom/maven/yflistrecyclerview/view
compile 'com.android.support:recyclerview-v7:22.2.0'
compile 'com.yefeng:yf_list_recycler_view:1.1.0'
new a RecyclerViewAdapter, and override the method whitch you want to use, just like SampleActivity do...
public class DemoAdapter extends YfListAdapter<String> {
public DemoAdapter(ArrayList<String> data) {
super(data);
}
@Override
public RecyclerView.ViewHolder onCreateDataViewHolder(ViewGroup parent) {
View view = LayoutInflater.from(parent.getContext()).inflate(R.layout.adapter_item, parent, false);
return new ViewHolder(view);
}
@Override
public RecyclerView.ViewHolder onCreateEmptyViewHolder(ViewGroup parent) {
View view = LayoutInflater.from(parent.getContext()).inflate(R.layout.view_empty_material, parent, false);
return new YfSimpleViewHolder(view);
}
@Override
public void onBindDataViewHolder(RecyclerView.ViewHolder viewHolder, int i) {
((ViewHolder) viewHolder).mText.setText(mData.get(i));
viewHolder.itemView.setTag(mData.get(i));
}
private static final class ViewHolder extends RecyclerView.ViewHolder {
TextView mText;
public ViewHolder(final View itemView) {
super(itemView);
mText = (TextView) itemView.findViewById(R.id.txt_adapter_item);
}
}
}
mRecycler.setAdapter(new DemoAdapter(list_data));
mList.setDivider(R.drawable.divider);
mList.enableAutoLoadMore(new YfLoadMoreListener() {
@Override
public void loadMore() {
}
});
use ExpansionLinearLayoutManager to replace LinearLayoutManager
ExpansionLinearLayoutManager layoutManager = new ExpansionLinearLayoutManager(getApplicationContext(), LinearLayoutManager.VERTICAL, false);
recyclerView.setLayoutManager(layoutManager);
show data. if data is empty, empty view will display.
mAdapter.setData(mData);
show loading
mAdapter.changeMode(RecyclerViewMode.MODE_LOADING);
show error
mAdapter.changeMode(RecyclerViewMode.MODE_ERROR)
override onCreateHeaderViewHolder and onBindHeaderViewHolder or onCreateFooterViewHolder and onBindFooterViewHolder method
@Override
public RecyclerView.ViewHolder onCreateHeaderViewHolder(ViewGroup parent) {
View view = LayoutInflater.from(parent.getContext()).inflate(R.layout.view_header1, parent, false);
return new SimpleViewHolder(view);
}
@Override
public void onBindHeaderViewHolder(RecyclerView.ViewHolder holder, int position) {
((TextView) holder.itemView.findViewById(R.id.tv_header)).setText(mAdapter.getHeaders().get(position).toString());
holder.itemView.setTag(mAdapter.getHeaders().get(position).toString());
}
@Override
public RecyclerView.ViewHolder onCreateFooterViewHolder(ViewGroup parent) {
View view = LayoutInflater.from(parent.getContext()).inflate(R.layout.view_footer1, parent, false);
return new SimpleViewHolder(view);
}
@Override
public void onBindFooterViewHolder(RecyclerView.ViewHolder holder, int position) {
((TextView) holder.itemView.findViewById(R.id.tv_footer)).setText(mAdapter.getFooters().get(position).toString());
holder.itemView.setTag(mAdapter.getFooters().get(position).toString());
}
call adapter's addHeader or addFooter method
!!! make sure your adapter is in RecyclerViewMode.MODE_DATA
mAdapter.addHeader("header 1");
mAdapter.removeHeader(header);
mAdapter.addFooter("footer 1");
mAdapter.removeFooter(footer);