Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix the bug that apdapter delay to call setOnItemClickListener() that… #2708

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,7 @@ public abstract class BaseQuickAdapter<T, K extends BaseViewHolder> extends Recy
private LoadMoreView mLoadMoreView = new SimpleLoadMoreView();
private RequestLoadMoreListener mRequestLoadMoreListener;
private boolean mEnableLoadMoreEndClick = false;
private List<K> mViewHolders;

//Animation
/**
Expand Down Expand Up @@ -476,6 +477,7 @@ public BaseQuickAdapter(@LayoutRes int layoutResId, @Nullable List<T> data) {
if (layoutResId != 0) {
this.mLayoutResId = layoutResId;
}
mViewHolders = new ArrayList<>();
}

public BaseQuickAdapter(@Nullable List<T> data) {
Expand Down Expand Up @@ -780,6 +782,7 @@ public K onCreateViewHolder(ViewGroup parent, int viewType) {
default:
baseViewHolder = onCreateDefViewHolder(parent, viewType);
bindViewClickListener(baseViewHolder);
mViewHolders.add(baseViewHolder);
}
baseViewHolder.setAdapter(this);
return baseViewHolder;
Expand Down Expand Up @@ -967,15 +970,19 @@ private void bindViewClickListener(final BaseViewHolder baseViewHolder) {
view.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
setOnItemClick(v, baseViewHolder.getLayoutPosition() - getHeaderLayoutCount());
if (getOnItemClickListener() != null) {
setOnItemClick(v, baseViewHolder.getLayoutPosition() - getHeaderLayoutCount());
}
}
});
}
if (getOnItemLongClickListener() != null) {
view.setOnLongClickListener(new View.OnLongClickListener() {
@Override
public boolean onLongClick(View v) {
return setOnItemLongClick(v, baseViewHolder.getLayoutPosition() - getHeaderLayoutCount());
if (getOnItemLongClickListener() != null)
return setOnItemLongClick(v, baseViewHolder.getLayoutPosition() - getHeaderLayoutCount());
return false;
}
});
}
Expand Down Expand Up @@ -1152,7 +1159,7 @@ public int addHeaderView(View header, int index) {
* @param index
* @param orientation
*/
public int addHeaderView(View header,final int index, int orientation) {
public int addHeaderView(View header, final int index, int orientation) {
if (mHeaderLayout == null) {
mHeaderLayout = new LinearLayout(header.getContext());
if (orientation == LinearLayout.VERTICAL) {
Expand All @@ -1164,7 +1171,7 @@ public int addHeaderView(View header,final int index, int orientation) {
}
}
final int childCount = mHeaderLayout.getChildCount();
int mIndex =index;
int mIndex = index;
if (index < 0 || index > childCount) {
mIndex = childCount;
}
Expand Down Expand Up @@ -1930,6 +1937,7 @@ public int getParentPosition(@NonNull T item) {
public interface OnItemChildClickListener {
/**
* callback method to be invoked when an itemchild in this view has been click
*
* @param adapter
* @param view The view whihin the ItemView that was clicked
* @param position The position of the view int the adapter
Expand All @@ -1946,6 +1954,7 @@ public interface OnItemChildLongClickListener {
/**
* callback method to be invoked when an item in this view has been
* click and held
*
* @param adapter this BaseQuickAdapter adapter
* @param view The childView whihin the itemView that was clicked and held.
* @param position The position of the view int the adapter
Expand Down Expand Up @@ -1998,6 +2007,9 @@ public interface OnItemClickListener {
*/
public void setOnItemClickListener(@Nullable OnItemClickListener listener) {
mOnItemClickListener = listener;
for (BaseViewHolder viewHolder : mViewHolders) {
bindViewClickListener(viewHolder);
}
}

/**
Expand All @@ -2018,6 +2030,9 @@ public void setOnItemChildClickListener(OnItemChildClickListener listener) {
*/
public void setOnItemLongClickListener(OnItemLongClickListener listener) {
mOnItemLongClickListener = listener;
for (BaseViewHolder viewHolder : mViewHolders) {
bindViewClickListener(viewHolder);
}
}

/**
Expand Down