diff --git a/ByRecyclerview/src/main/java/me/jingbin/library/adapter/BaseByRecyclerViewAdapter.java b/ByRecyclerview/src/main/java/me/jingbin/library/adapter/BaseByRecyclerViewAdapter.java index 40e3422..260d069 100644 --- a/ByRecyclerview/src/main/java/me/jingbin/library/adapter/BaseByRecyclerViewAdapter.java +++ b/ByRecyclerview/src/main/java/me/jingbin/library/adapter/BaseByRecyclerViewAdapter.java @@ -30,6 +30,7 @@ protected BaseByRecyclerViewAdapter(List data) { @Override public void onBindViewHolder(@NonNull K holder, final int position) { + holder.setByRecyclerView(mRecyclerView); holder.onBaseBindView(holder, mData.get(position), position); } diff --git a/ByRecyclerview/src/main/java/me/jingbin/library/adapter/BaseByViewHolder.java b/ByRecyclerview/src/main/java/me/jingbin/library/adapter/BaseByViewHolder.java index d05ccd7..74c9d4f 100644 --- a/ByRecyclerview/src/main/java/me/jingbin/library/adapter/BaseByViewHolder.java +++ b/ByRecyclerview/src/main/java/me/jingbin/library/adapter/BaseByViewHolder.java @@ -403,6 +403,7 @@ public BaseByViewHolder addOnClickListener(@IdRes final int viewId) { view.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { + checkByRecyclerView(); if (byRecyclerView.getOnItemChildClickListener() != null) { byRecyclerView.getOnItemChildClickListener().onItemChildClick(v, getClickPosition()); } @@ -429,6 +430,7 @@ public BaseByViewHolder addOnLongClickListener(@IdRes final int viewId) { view.setOnLongClickListener(new View.OnLongClickListener() { @Override public boolean onLongClick(View v) { + checkByRecyclerView(); return byRecyclerView.getOnItemChildLongClickListener() != null && byRecyclerView.getOnItemChildLongClickListener().onItemChildLongClick(v, getClickPosition()); } @@ -451,4 +453,10 @@ public BaseByViewHolder setByRecyclerView(ByRecyclerView byRecyclerView) { this.byRecyclerView = byRecyclerView; return this; } + + private void checkByRecyclerView() { + if (byRecyclerView == null) { + throw new IllegalStateException("byRecyclerView is null! Please use setByRecyclerView() bind!"); + } + } }