Android 入门项目(八)Android 流式筛选弹框,android 应用程序开发的流程
/**
Created by zhangyan 2021/01/29
*/
public class FlowPopRecyclerViewAdapter extends RecyclerView.Adapter<FlowPopRecyclerViewAdapter.FlowPopViewHolder> {
private Context mContext;
private List<FiltrateBean> mData;
public FlowPopRecyclerViewAdapter(Context context) {
mData = new ArrayList<>();
this.mContext = context;
}
@NonNull
@Override
public FlowPopViewHolder onCreateViewHolder(@NonNull ViewGroup viewGroup, int i) {
FlowPopViewHolder viewHolder = new FlowPopViewHolder(LayoutInflater.from(mContext).inflate(R.layout.item_listview_property, viewGroup, false));
return viewHolder;
}
@Override
public void onBindViewHolder(@NonNull FlowPopRecyclerViewAdapter.FlowPopViewHolder viewHolder, int i) {
FlowPopViewHolder vh = (FlowPopViewHolder) viewHolder;
FiltrateBean item = mData.get(i);
vh.tvTypeName.setText(item.getTypeName());
setFlowLayoutData(item.getChildren(), vh.layoutProperty);
}
@Override
public int getItemCount() {
return mData == null ? 0 : mData.size();
}
public static class FlowPopViewHolder extends RecyclerView.ViewHolder {
private TextView tvTypeName;
private SkuFlowLayout layoutProperty;
public FlowPopViewHolder(@NonNull View itemView) {
super(itemView);
tvTypeName = itemView.findViewById(R.id.tv_type_name);
layoutProperty = itemView.findViewById(R.id.layout_property);
}
}
private void setFlowLayoutData(final List<FiltrateBean.Children> childrenList, final SkuFlowLayout flowLayout) {
flowLayout.removeAllViews();
for (int x = 0; x < childrenList.size(); x++) {
CheckBox checkBox = (CheckBox) View.inflate(mContext, R.layout.item_flowlayout_bill, null);
checkBox.setText(childrenList.get(x).getValue());
if (childrenList.get(x).isSelected()) {
checkBox.setChecked(true);
childrenList.get(x).setSelected(true);
} else {
checkBox.setChecked(false);
childrenList.get(x).setSelected(false);
}
final int finalX = x;
checkBox.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
refreshCheckBox(flowL
ayout, finalX, childrenList);
}
});
flowLayout.addView(checkBox);
}
}
private void refreshCheckBox(SkuFlowLayout flowLayout, int finalX, List<FiltrateBean.Children> propBeenList) {
for (int y = 0; y < flowLayout.getChildCount(); y++) {
CheckBox radio = (CheckBox) flowLayout.getChildAt(y);
radio.setChecked(false);
propBeenList.get(y).setSelected(false);
if (finalX == y) {
radio.setChecked(true);
propBeenList.get(y).setSelected(true);
}
}
}
/**
设置数据
@param data
*/
public void setData(List<FiltrateBean> data){
mData.clear();
mData.addAll(data);
notifyDataSetChanged();
}
/**
清空数据
*/
public void clearData(){
mData.clear();
notifyDataSetChanged();
}
}
流式布局的测量
@Override
protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
int sizeWidth = MeasureSpec.getSize(widthMeasureSpec);
int modeWidth = MeasureSpec.getMode(widthMeasureSpec);
int sizeHeight = MeasureSpec.getSize(heightMeasureSpec);
int modeHeight = MeasureSpec.getMode(heightMeasureSpec);
int width = 0;
int height = 0;
int lineWidth = 0;
评论