Skip to content

Commit d36408f

Browse files
committed
1.Decoupling click events
2. Adopt suggestions CymChad#1699
1 parent ee6500e commit d36408f

File tree

1 file changed

+23
-4
lines changed

1 file changed

+23
-4
lines changed

library/src/main/java/com/chad/library/adapter/base/BaseQuickAdapter.java

Lines changed: 23 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -953,20 +953,39 @@ private void bindViewClickListener(final BaseViewHolder baseViewHolder) {
953953
view.setOnClickListener(new View.OnClickListener() {
954954
@Override
955955
public void onClick(View v) {
956-
getOnItemClickListener().onItemClick(BaseQuickAdapter.this, v, baseViewHolder.getLayoutPosition() - getHeaderLayoutCount());
956+
setOnItemClick(v, baseViewHolder.getLayoutPosition() - getHeaderLayoutCount());
957957
}
958958
});
959959
}
960960
if (getOnItemLongClickListener() != null) {
961961
view.setOnLongClickListener(new View.OnLongClickListener() {
962962
@Override
963963
public boolean onLongClick(View v) {
964-
return getOnItemLongClickListener().onItemLongClick(BaseQuickAdapter.this, v, baseViewHolder.getLayoutPosition() - getHeaderLayoutCount());
964+
return setOnItemLongClick(v, baseViewHolder.getLayoutPosition() - getHeaderLayoutCount());
965965
}
966966
});
967967
}
968968
}
969969

970+
/**
971+
* override this method if you want to override click event logic
972+
* @param v
973+
* @param position
974+
*/
975+
public void setOnItemClick(View v, int position) {
976+
getOnItemClickListener().onItemClick(BaseQuickAdapter.this, v, position);
977+
}
978+
979+
/**
980+
* override this method if you want to override longClick event logic
981+
* @param v
982+
* @param position
983+
* @return
984+
*/
985+
public boolean setOnItemLongClick(View v, int position) {
986+
return getOnItemLongClickListener().onItemLongClick(BaseQuickAdapter.this, v, position);
987+
}
988+
970989
private MultiTypeDelegate<T> mMultiTypeDelegate;
971990

972991
public void setMultiTypeDelegate(MultiTypeDelegate<T> multiTypeDelegate) {
@@ -1687,7 +1706,7 @@ public int expandAll(int position, boolean animate, boolean notify) {
16871706
return 0;
16881707
}
16891708

1690-
if(!hasSubItems(expandable)){
1709+
if (!hasSubItems(expandable)) {
16911710
expandable.setExpanded(true);
16921711
notifyItemChanged(position);
16931712
return 0;
@@ -1744,7 +1763,7 @@ private int recursiveCollapse(@IntRange(from = 0) int position) {
17441763
int subItemCount = 0;
17451764
if (expandable.isExpanded()) {
17461765
List<T> subItems = expandable.getSubItems();
1747-
if(null == subItems) return 0;
1766+
if (null == subItems) return 0;
17481767

17491768
for (int i = subItems.size() - 1; i >= 0; i--) {
17501769
T subItem = subItems.get(i);

0 commit comments

Comments
 (0)