Skip to content
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
23 changes: 23 additions & 0 deletions library/src/main/java/com/hhl/library/FlowTagLayout.java
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,11 @@ public class FlowTagLayout extends ViewGroup {
*/
private int mTagCheckMode = FLOW_TAG_CHECKED_NONE;

/**
* 标签流式布局最多选中Tag数,默认为Integer.MAX_VALUE
*/
private int mMaxSelectTagNum = Integer.MAX_VALUE;

/**
* 存储选中的tag
*/
Expand Down Expand Up @@ -268,6 +273,15 @@ public void onClick(View v) {
mCheckedTagArray.put(j, false);
childView.setSelected(false);
} else {
int selectTagNum = 0;
for (int k = 0; k < mAdapter.getCount(); k++) {
if (mCheckedTagArray.get(k)) {
selectTagNum++;
}
}
if (selectTagNum >= mMaxSelectTagNum) {
return;
}
mCheckedTagArray.put(j, true);
childView.setSelected(true);
}
Expand Down Expand Up @@ -332,4 +346,13 @@ public int getmTagCheckMode() {
public void setTagCheckedMode(int tagMode) {
this.mTagCheckMode = tagMode;
}

/**
* 设置最多可选标签数
*
* @param num
*/
public void setMaxSelectTagNum(int num) {
this.mMaxSelectTagNum = num;
}
}