I am struggling with a problem. I have an activity that has a RecyclerView with images. The RecyclerView is filled throught adapter, and that's works fine, and I got his starting screen.
After this I want to change this images in a loop with a pause of 2 seconds randomly. That is where I need help, because what I already tried, showed the end screen immediately, there is time between 2 image changes, and this is what shows.
I am trying this to achieve in the onStart function calling hideElements() function. Here is my hideElements() function:
private fun hideElements()
{
if(recyclerView.adapter?.itemCount == 0)
{
return
}
var hideOrdder: ArrayList<Int> = ArrayList<Int>()
for (i in 0 until recyclerView.adapter?.itemCount!!)
{
hideOrdder.add(i)
}
hideOrdder.shuffle()
for(i in hideOrdder)
{
_gridElementList[i].drawableId = R.drawable.kerojel
handler = Handler()
runnable = Runnable {
adapter!!.notifyItemChanged(i)
}
runOnUiThread {
handler!!.postDelayed(runnable!!, 10000)
}
}
}
I tried also to create a thread, but I failed. thnx


You are changing whole dataset
_gridElementListin one go inside loop . Thats not right. There can be multiple solution . You can usehandlerand aTimer. posting a solution with handler. its not elegant but it should do the job. I have set one delayed call with handler and setting subsequent call when it fires after 2 seconds.you need to save
hideOrderbeforehand at class level . and this should work. its not the complete code but you get the idea . Do make sure you callhandler.removeCallbacks(runnable)inonDestroy().