Skip to content

Commit

Permalink
Add HeadViewandEmptyView Case
Browse files Browse the repository at this point in the history
  • Loading branch information
ChadCym committed May 20, 2016
1 parent 4a39d3f commit e8dce08
Showing 1 changed file with 12 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ public abstract class BaseQuickAdapter<T> extends RecyclerView.Adapter<RecyclerV
private boolean mFirstOnlyEnable = true;
private boolean mOpenAnimationEnable = false;
private boolean mEmptyEnable;
private boolean mHeadAndEmptyEnable;
private Interpolator mInterpolator = new LinearInterpolator();
private int mDuration = 300;
private int mLastPosition = -1;
Expand Down Expand Up @@ -109,6 +110,10 @@ public void setOnLoadMoreListener(RequestLoadMoreListener requestLoadMoreListene
this.mRequestLoadMoreListener = requestLoadMoreListener;
}

public void setDuration(int duration) {
mDuration = duration;
}

/**
* when adapter's data size than pageSize and enable is true,the loading more function is enable,or disable
*
Expand Down Expand Up @@ -290,7 +295,7 @@ public int getItemCount() {
int i = isLoadMore() ? 1 : 0;
int count = mData.size() + i + getHeaderViewsCount() + getFooterViewsCount();
mEmptyEnable = false;
if (count == 0) {
if ((mHeadAndEmptyEnable && getHeaderViewsCount() == 1 && count == 1) || count == 0) {
mEmptyEnable = true;
count += getmEmptyViewCount();
}
Expand All @@ -302,7 +307,7 @@ public int getItemCount() {
public int getItemViewType(int position) {
if (mHeaderView != null && position == 0) {
return HEADER_VIEW;
} else if (mEmptyView != null && getItemCount() == 1 && mEmptyEnable) {
} else if (mEmptyView != null && getItemCount() == (mHeadAndEmptyEnable ? 2 : 1) && mEmptyEnable) {
return EMPTY_VIEW;
} else if (position == mData.size() + getHeaderViewsCount()) {
if (mNextLoadEnable)
Expand Down Expand Up @@ -423,6 +428,11 @@ public void addFooterView(View footer) {
* Sets the view to show if the adapter is empty
*/
public void setEmptyView(View emptyView) {
setEmptyView(false, emptyView);
}

public void setEmptyView(boolean isHeadAndEmpty, View emptyView) {
mHeadAndEmptyEnable = isHeadAndEmpty;
mEmptyView = emptyView;
}

Expand Down

0 comments on commit e8dce08

Please sign in to comment.