Skip to content
Advertisement

Java – getCardBackgroundColor – color for CardView

Can you help me with my code? I am changing the color of the item based on the information from the database, and now I wanted to transfer the color to the CardView, but I don’t know what the notation should look like, because this code tells me that the Color.RED write is wrong. Will you help me?

 @Override
protected void onBindViewHolder(@NonNull holder holder, int position, @NonNull 
VoiceModel model) {

    holder.tvvoiceName.setText(model.getName());
    holder.tvvoiceTime.setText(model.getTime());
    if(model.getPremium() == 1) holder.voice_item.getCardBackgroundColor(Color.RED);

Advertisement

Answer

You have to use setCardBackgroundColor not getCardBackgroundColor. Then your code should be:

holder.voice_item.setCardBackgroundColor(Color.RED);
User contributions licensed under: CC BY-SA
8 People found this is helpful
Advertisement