binding.llGoods.removeAllViews();
for (int i = 0; i < entries.length; i++) {
LegendEntry entry = entries[i];
View view = View.inflate(getActivity(), R.layout.item_good, null);
TextView icon=view.findViewById(R.id.icon);
TextView goodName=view.findViewById(R.id.goodName);
TextView totalMoney=view.findViewById(R.id.totalMoney);
icon.setBackgroundColor(Color.parseColor(ColorUtil.int2Hex(entry.formColor)));
goodName.setText(entry.label);
totalMoney.setText("111元");
binding.llGoods.addView(view);
Log.e("syw", "entry.label:" + entry.label + "formColor:" + ColorUtil.int2Hex(entry.formColor));
}
以前为了方便,在for循环之前填充一个view,在for循环内设置信息,报错.
把填充view写到for循环内部就可以了
本文介绍了一种解决UI列表动态加载时出现的错误的方法。通过将视图填充操作从循环外移至循环内,成功避免了报错,确保了每个列表项的正确显示。
2739

被折叠的 条评论
为什么被折叠?



