【发布时间】:2018-02-18 20:10:56
【问题描述】:
我想更改 Recycler 查看状态为 Ture 的数据的背景颜色为绿色,并设置状态为 False 的背景颜色为红色。
第一轮状态为真,其余为假。 那么谁能告诉我我是如何区分的......
我的回收站查看代码写在下面。
@Override
public void onBindViewHolder(DocRecycleAdoptor.MyViewHolder holder, int position) {
final EmpAttandance empAttandance = mDocs.get(position);
holder.txtDocID.setText(empAttandance.getDOC_ID());
holder.txtEmpID.setText(empAttandance.getEMP_ID());
holder.dateTime.setText(empAttandance.getDATE()+" "+empAttandance.getTIME());
holder.txtCoID.setText(empAttandance.getCO_ID());
holder.txtStatus.setText(empAttandance.getSA());
holder.empName.setText(empAttandance.getEmpName());
if(empAttandance.getStatus() == "True"){
holder.itemView.setBackgroundColor(Color.GREEN);
}else{
holder.itemView.setBackgroundColor(Color.RED);
}
}
现在它显示为这样。 但我想当状态为假时颜色会变红。 它确实发生了。 前三个状态为真,其他为假。 以相同的颜色显示所有内容
【问题讨论】:
-
在 list.getStatus 的 onbind 检查中 == true ..更改 bgcolor.. 否则将 bgcolor 更改为白色
-
您在 xml 中为布局提供了白色背景。如果你删除它,那么它应该可以工作。
-
请发布您的项目 xml
标签: android