中文版文档)
BaseRecyclerViewAdapterHelper(Powerful and flexible RecyclerAdapter Please feel free to use this.(Love can be a Star) #Features(download apk)
- Reduce lot of code.easily create RecyclerAdapter
- add item click and add item long click
- easily add RecyclerAdapter animations
- add HeadView and add FooterView
- add The drop-down refresh, load more
- easily create section headers
- custom item view type
- add setEmptyView methods
- add item chlid click
Get it
Add it in your root build.gradle at the end of repositories:
allprojects {
repositories {
...
maven { url "https://jitpack.io" }
}
}
Add the dependency
dependencies {
compile 'com.github.CymChad:BaseRecyclerViewAdapterHelper:v1.6.6'
}
#Use it create RecyclerAdapter
public class QuickAdapter extends BaseQuickAdapter<Status> {
public QuickAdapter(Context context) {
super(context, R.layout.tweet, DataServer.getSampleData());
}
@Override
protected void convert(BaseViewHolder helper, Status item) {
helper.setText(R.id.tweetName, item.getUserName())
.setText(R.id.tweetText, item.getText())
.setText(R.id.tweetDate, item.getCreatedAt())
.setImageUrl(R.id.tweetAvatar, item.getUserAvatar())
.setVisible(R.id.tweetRT, item.isRetweet())
.linkify(R.id.tweetText);
}
}
#Use it item click
mQuickAdapter.setOnRecyclerViewItemClickListener(new BaseQuickAdapter.OnRecyclerViewItemClickListener() {
@Override
public void onItemClick(View view, int position) {
//..
}
});
#Use it add adaptar Animation
// Turn animation
quickAdapter.openLoadAnimation();
or
// Turn animation and set animate
quickAdapter.openLoadAnimation(BaseQuickAdapter.ALPHAIN);
or
// Turn animation and set custom animate
quickAdapter.openLoadAnimation(new BaseAnimation() {
@Override
public Animator[] getAnimators(View view) {
return new Animator[]{
ObjectAnimator.ofFloat(view, "scaleY", 1, 1.1f, 1),
ObjectAnimator.ofFloat(view, "scaleX", 1, 1.1f, 1)
};
}
});
#Use it custom item view type
public class MultipleItemQuickAdapter extends BaseMultiItemQuickAdapter<MultipleItem> {
public MultipleItemQuickAdapter(Context context, List data) {
super(context, data);
addItmeType(MultipleItem.TEXT, R.layout.text_view);
addItmeType(MultipleItem.IMG, R.layout.image_view);
}
@Override
protected void convert(BaseViewHolder helper, MultipleItem item) {
switch (helper.getItemViewType()) {
case MultipleItem.TEXT:
helper.setImageUrl(R.id.tv, item.getContent());
break;
case MultipleItem.IMG:
helper.setImageUrl(R.id.iv, item.getContent());
break;
}
}
}
#Use it add header and footer
mQuickAdapter.addHeaderView(getView());
mQuickAdapter.addFooterView(getView());
#Use it load more setOnLoadMoreListener
mQuickAdapter.setOnLoadMoreListener(this);
Override onLoadMoreRequested()
@Override
public void onLoadMoreRequested() {
mRecyclerView.post(new Runnable() {
@Override
public void run() {
if (mCurrentCounter >= TOTAL_COUNTER) {
mQuickAdapter.notifyDataChangedAfterLoadMore(false);
}
} else {
mQuickAdapter.notifyDataChangedAfterLoadMore(DataServer.getSampleData(PAGE_SIZE),true);
mCurrentCounter = mQuickAdapter.getItemCount();
}});
}
#Use it create section headers
public class SectionAdapter extends BaseSectionQuickAdapter<MySection> {
public SectionAdapter(Context context, int layoutResId, int sectionHeadResId, List data) {
super(context, layoutResId, sectionHeadResId, data);
}
@Override
protected void convert(BaseViewHolder helper, MySection item) {
helper.setImageUrl(R.id.iv, (String) item.t);
}
@Override
protected void convertHead(BaseViewHolder helper,final MySection item) {
helper.setText(R.id.header, item.header);
if(!item.isMroe)helper.setVisible(R.id.more,false);
else
helper.setOnClickListener(R.id.more, new View.OnClickListener() {
@Override
public void onClick(View v) {
Toast.makeText(context,item.header+"more..",Toast.LENGTH_LONG).show();
}
});
}
#Use it setEmptyView
mQuickAdapter.setEmptyView(getView());
#Use it item chlid click Adapter
protected void convert(BaseViewHolder helper, Status item) {
helper.setOnClickListener(R.id.tweetAvatar, new OnItemChildClickListener())
.setOnClickListener(R.id.tweetName, new OnItemChildClickListener());
}
Activity
mQuickAdapter.setOnRecyclerViewItemChildClickListener(new BaseQuickAdapter.OnRecyclerViewItemChildClickListener() {
@Override
public void onItemChildClick(BaseQuickAdapter adapter, View view, int position) {
String content = null;
Status status = (Status) adapter.getItem(position);
switch (view.getId()) {
case R.id.tweetAvatar:
content = "img:" + status.getUserAvatar();
break;
case R.id.tweetName:
content = "name:" + status.getUserName();
break;
}
Toast.makeText(AnimationUseActivity.this, content, Toast.LENGTH_LONG).show();
}
});
#Thanks JoanZapata / base-adapter-helper