I am new in android , recently I have learned recyclerview and i want to change the color of rows.
Example: I have 10 rows and I want to change color like
I believe one problem with all of these solutions is that onBindViewHolder doesn't get called in certain cases. If you use notify methods like notifyItemInserted(int position), you could potentially have rows stacked on top of each other with the same color - no good. You will need to call notifyItemChanged on every other item to re-render the background color corresponding to the new position.
Using the re-render all method notifyDataSetChanged() will fix this (but is less efficient than only updating specific rows), and if you don't dynamically change the contents of a RecyclerAdapter while the user is on the screen, you won't have this issue.