我想更改背景Colo of Specific Recycler VIew Item

时间:2018-02-18 20:10:57

标签: android

我想更改状态为False的Recycler View数据的背景颜色绿色和设置背景颜色RED的状态为False。 enter image description here

第一轮状态为真,其余为假。 所以任何人都可以告诉我,我如何区分......

我的Recycler查看代码在下面写。

@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);
    }
}

enter image description here

现在它显示为This。 但我希望当状态为假时颜色会变红。 它确实很好。 前三名状态为真,其他是假。 显示所有颜色相同

4 个答案:

答案 0 :(得分:0)

在你的onBindViewHolder中添加以下内容

if(empAttandance.getStatus()){
//set your desired color on textview or a view for status true
}else{
//set your desired color on textview or a view for status false
}

答案 1 :(得分:0)

@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());

   // this is it
 holder.rootLayout.setBackgroundColor(empAttandance.getStatus() ? GREEN : RED);

 }

答案 2 :(得分:0)

// Remove a specific key from the cookie value
cookie.Values.Remove(ID.Value.ToString());

答案 3 :(得分:0)

在ANdroid ==不工作。所以我使用empAttandance.getStatus().equal("True")代替==并且它的工作正常。

感谢各位大家帮助我。非常感谢。

if(empAttandance.getStatus().equal("True")){
//set your desired color on textview or a view for status true
}else{
//set your desired color on textview or a view for status false
}