写点什么

Android 入门项目(八)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


《Android学习笔记总结+最新移动架构视频+大厂安卓面试真题+项目实战源码讲义》
浏览器打开:qq.cn.hn/FTe 免费领取
复制代码


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;

用户头像

Android架构

关注

还未添加个人签名 2021.10.31 加入

还未添加个人简介

评论

发布
暂无评论
Android入门项目(八)Android流式筛选弹框,android应用程序开发的流程