diff --git a/library/src/main/java/com/chad/library/adapter/base/BaseMultiItemQuickAdapter.java b/library/src/main/java/com/chad/library/adapter/base/BaseMultiItemQuickAdapter.java index 008776e85..1458c3568 100644 --- a/library/src/main/java/com/chad/library/adapter/base/BaseMultiItemQuickAdapter.java +++ b/library/src/main/java/com/chad/library/adapter/base/BaseMultiItemQuickAdapter.java @@ -15,7 +15,6 @@ * https://github.com/CymChad/BaseRecyclerViewAdapterHelper */ public abstract class BaseMultiItemQuickAdapter extends BaseQuickAdapter { - protected List mData; private SparseArray layouts; /** @@ -32,7 +31,7 @@ public BaseMultiItemQuickAdapter(Context context, List data) { @Override protected int getDefItemViewType(int position) { - return mData.get(position).getItemType(); + return ((MultiItemEntity)mData.get(position)).getItemType(); } @@ -54,6 +53,8 @@ protected void addItmeType(int type, int layoutResId) { layouts.put(type, layoutResId); } + + @Override protected void convert(BaseViewHolder helper, Object item) { convert(helper, (T) item); diff --git a/library/src/main/java/com/chad/library/adapter/base/BaseQuickAdapter.java b/library/src/main/java/com/chad/library/adapter/base/BaseQuickAdapter.java index f23349d0a..bc6871579 100755 --- a/library/src/main/java/com/chad/library/adapter/base/BaseQuickAdapter.java +++ b/library/src/main/java/com/chad/library/adapter/base/BaseQuickAdapter.java @@ -71,6 +71,8 @@ public abstract class BaseQuickAdapter extends RecyclerView.Adapter mData; private Interpolator mInterpolator = new LinearInterpolator(); @@ -198,6 +200,7 @@ public void onClick(View v) { public BaseQuickAdapter(Context context, int layoutResId, List data) { this.mData = data == null ? new ArrayList() : new ArrayList(data); this.mContext = context; + this.mLayoutInflater = LayoutInflater.from(context); if (layoutResId != 0) { this.mLayoutResId = layoutResId; } @@ -417,22 +420,22 @@ public void notifyDataChangedAfterLoadMore(boolean isNextLoad) { @Override - public void onBindViewHolder(RecyclerView.ViewHolder holder, final int position) { + public void onBindViewHolder(final RecyclerView.ViewHolder holder, int positions) { if (holder instanceof ContentViewHolder) { - int index = position - getHeaderViewsCount(); + int index = holder.getLayoutPosition() - getHeaderViewsCount(); BaseViewHolder baseViewHolder = (BaseViewHolder) holder; convert(baseViewHolder, mData.get(index)); if (onRecyclerViewItemClickListener != null) { baseViewHolder.convertView.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { - onRecyclerViewItemClickListener.onItemClick(v, position - getHeaderViewsCount()); + onRecyclerViewItemClickListener.onItemClick(v, holder.getLayoutPosition() - getHeaderViewsCount()); } }); } if (mOpenAnimationEnable) { - if (!mFirstOnlyEnable || position > mLastPosition) { + if (!mFirstOnlyEnable || holder.getLayoutPosition() > mLastPosition) { BaseAnimation animation = null; if (mCustomAnimation != null) { animation = mCustomAnimation; @@ -443,7 +446,7 @@ public void onClick(View v) { anim.setDuration(mDuration).start(); anim.setInterpolator(mInterpolator); } - mLastPosition = position; + mLastPosition = holder.getLayoutPosition(); } } } else if (holder instanceof FooterViewHolder) { @@ -461,7 +464,7 @@ public void onClick(View v) { } else if (holder instanceof EmptyViewHolder) { } else { - int index = position - getHeaderViewsCount(); + int index = holder.getLayoutPosition() - getHeaderViewsCount(); BaseViewHolder baseViewHolder = (BaseViewHolder) holder; onBindDefViewHolder(baseViewHolder, mData.get(index)); } @@ -472,8 +475,7 @@ private boolean isLoadMore() { } protected View getItemView(int layoutResId, ViewGroup parent) { - return LayoutInflater.from(parent.getContext()).inflate( - layoutResId, parent, false); + return mLayoutInflater.inflate(layoutResId, parent, false); } diff --git a/library/src/main/java/com/chad/library/adapter/base/BaseSectionQuickAdapter.java b/library/src/main/java/com/chad/library/adapter/base/BaseSectionQuickAdapter.java index 474247a37..719069caf 100755 --- a/library/src/main/java/com/chad/library/adapter/base/BaseSectionQuickAdapter.java +++ b/library/src/main/java/com/chad/library/adapter/base/BaseSectionQuickAdapter.java @@ -17,7 +17,6 @@ public abstract class BaseSectionQuickAdapter extends B protected int mSectionHeadResId; - protected List mData; protected static final int SECTION_HEADER_VIEW = 0x00000444; /** @@ -39,7 +38,7 @@ public BaseSectionQuickAdapter(Context context, int layoutResId, int sectionHead @Override protected int getDefItemViewType(int position) { - return mData.get(position).isHeader ? SECTION_HEADER_VIEW : 0; + return ((SectionEntity)mData.get(position)).isHeader ? SECTION_HEADER_VIEW : 0; } @Override @@ -69,6 +68,7 @@ protected void onBindDefViewHolder(BaseViewHolder holder, Object item) { } } + @Override protected void convert(BaseViewHolder helper, Object item) { convert(helper, (T) item);