How To Show Random Data Every Time In Recyclerview From Arraylist
How do I show random data everytime I open recyclerview For example if I have a arraylist of name arraydata={a,b,c,d,e,f,g,h,i,j,k,l} In recyclerview it always show in sequence ma
Solution 1:
You can use Collections
to shuffle your array list of data before passing it to your RecyclerView.Adapter
:
Collections.shuffle(arraylistobject)
Solution 2:
You can use Random
class from java.util
package, it's nextInt()
method returns pseudorandomint
value in range from 0 inclusive to value passed as argument exclusive:
import java.util.*;
Randomrand=newRandom();
holder.textitem.setText(arraylistobject.get(rand.nextInt(arraylistobject.size()).getTextFun());
rand.nextInt(arraylistobject.size())
in that case returns value from 0 to size of your arraylistobject
exclusive.
Post a Comment for "How To Show Random Data Every Time In Recyclerview From Arraylist"