android - Alternater color in row GridView -


i have gridview x elements.

my gridview has 2 columns. need color per row

[0] [1] - color white [2] [3] - color black [4] [5] - color white [6] [6] - color black 

i'm try in adapter, result not expected.

if (position %  numcoluns == 0) {            itemview.setbackgroundcolor(r.color.white)); else      itemview.setbackgroundcolor(r.color.black)); 

i'm try too, change rotate gridview using properties:

android:layoutdirection="rtl" android:stackfrombottom="true" 

anyone have idea? thanks.

edit - solution

if ((position /  numcoluns) %  2 == 0)  //color black else  color white 

you can row number using position / num columns. check if row number has changed each time in onbindview holder. if changed, u can change color else use previous color background.


Comments