Android-Listview items background color changing when scrolling

后端 未结 4 531
小蘑菇
小蘑菇 2021-01-14 17:41

My ListView contains two Textviews. In one row first one is for name and second one is for result. I need to change the background color of the re

4条回答
  •  青春惊慌失措
    2021-01-14 18:34

    You have to do something like this,

    if(Yourmark[position]<50) //Where Yourmark[] is the mark array you are passing to your custom adapter
    {
            holder.img.setImageResource(R.drawable.red_arrow);
            holder.txtViewDescription.setBackgroundResource(R.color.resultred);  
            holder.txtholder.setBackgroundResource(R.color.resultred);  
    }
    
    else
    {
            holder.img.setImageResource(R.drawable.green_arrow);
            holder.txtViewDescription.setBackgroundResource(R.color.resultgreen);  
            holder.txtholder.setBackgroundResource(R.color.resultgreen);  
    }
    }
    

提交回复
热议问题