I think you’re using the so-called "View Holder Pattern" and is reusing the Views using the Layoutinflater only when the parameter convertView
of the method getView()
of Adapter is null
.
So, how do you only assign the color to the backgroud when the position is even, when it reuses a View that previously was even in an odd position this keeps the color YELLOW
.
In order for the color toggle to work in these cases you must also assign the color to the background when the position is odd:
if(position % 2 == 0){
layout.setBackgroundColor(Color.YELLOW);
}
else{
layout.setBackgroundColor(Color.DasLinhasÍmpares);
}
Note:
The problem only occurs when there are more than 9 lines because that must be the number of lines that fit on the screen. When doing scroll as Views lines which are no longer visible may be reused by the Adapter and the problem begins.
Hello ramaral! That was the problem. It worked. Thank you.
– Vitor Mendanha