-1

how can I change color items with use condition for in recyclerview? my code does not work.

the recyclerView have a absent item and I want when absent count is 3, Item position changes.

RecyclerView Adapter:

 public class itemHolder extends RecyclerView.ViewHolder
 {
    TextView studentName ;
    TextView studentAbsent;

    public itemHolder(View itemView)
    {
        super(itemView);
    studentName = (TextView) itemView.findViewById(R.id.item_txt_StudentList_StudentName);
    absentButton = (Button)itemView.findViewById(R.id.item_btn_StudentList_Absent);
    }
}
@Override
public RecyclerView.ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {

    View view = LayoutInflater.from(context).inflate(R.layout.recyclerview_item_student_list, parent, false);

    return new itemHolder(view);
}


public void onBindViewHolder(final RecyclerView.ViewHolder holder, final int position) {

    itemHolder itemHolder = (itemHolder) holder;
    String studentName = performanceStudent.get(position).getStudentName();
    int aCount = performanceStudent.get(position).getAbsent();

    itemHolder.studentName.setText(String.valueOf(studentName));
    itemHolder.studentAbsent.setText(String.valueOf(aCount));

    if (aCount == 3)
    {                     holder.itemView.setBackgroundColor(Color.parseColor("#D50000"));//does not work
    }
}
Phantômaxx
  • 37,901
  • 21
  • 84
  • 115

1 Answers1

0

try this !

if (aCount == 3)
        {   
                  holder.studentAbsent.setBackgroundColor(Color.parseColor("#D50000"));//does not work
        }
iamkdblue
  • 3,448
  • 2
  • 25
  • 43