I am new to android, and I am having an issue with my recycler view. I want to have a random color as the profile image background, but the color keeps changing when I swipe up and down some couple of times, I want each item to maintain a particular color. Please how can I achieve this. This is what I have done to randomize the colors:
private fun changeClientProfileBackgroundColor ():Drawable?{val colorDrawables = arrayOf(
R.drawable.client_list_background_color_drawable_1,
R.drawable.client_list_background_color_drawable_2,
R.drawable.client_list_background_color_drawable_3,
R.drawable.client_list_background_color_drawable_4,
R.drawable.client_list_background_color_drawable_5,
R.drawable.client_list_background_color_drawable_6 )return ContextCompat.getDrawable(
context!!, colorDrawables[(Math.random() * 5).roundToInt()])}
binding.clientHomeImageProfileColorBackground.background =
changeClientProfileBackgroundColor()
Image of the recycler view with the background random colors