java - android how to get 4 images in array from ten array of image randomly -


i want 4 images array need same position images other array in example.

images = new int[] {     r.drawable.a, r.drawable.f, r.drawable.k,     r.drawable.u, r.drawable.y, r.drawable.w, r.drawable.t, r.drawable.g,     r.drawable.b, r.drawable.o };  images2 = new int[] {     r.drawable.apple, r.drawable.fan,     r.drawable.kite, r.drawable.umbrells,     r.drawable.yark,r.drawable.watch, r.drawable.tap,     r.drawable.gun, r.drawable.ball, r.drawable.orange }; 

i have 2 arrays of 10 pictures. need 5 images same both arrays randomly , same corresponding 5 images other array.

as need

array1={r.drawable.a, r.drawable.w,r.drawable.o,r.drawable.g} 

and same correspondence .

array2 = {r.drawable.apple, r.drawable.watch,r.drawable.orange,r.drawable.gun} 

this solution

arraylist<integer> list=new arraylist<integer>();         arraylist<integer> list1=new arraylist<integer>();         random r1=new random();         int[] images = new int[] {r.drawable.a, r.drawable.f, r.drawable.k,                 r.drawable.u, r.drawable.y, r.drawable.w, r.drawable.t, r.drawable.g,                 r.drawable.b, r.drawable.o};         int[] images2 = new int[] {  r.drawable.apple, r.drawable.fan,                 r.drawable.kite, r.drawable.umbrells,                 r.drawable.yark,r.drawable.watch, r.drawable.tap,                 r.drawable.gun, r.drawable.ball, r.drawable.orange};         for(int i=0;i<4;i++)         {             while(true)             {                 int next=r1.nextint(10)+1;                 if(!list.contains(next))                 {                 list.add(images[next]);                 list1.add(images2[next]);                 break;                 }             }         }         array1 = convertintegers(list);         array2 = convertintegers(list1); 

this convert function

public static int[] convertintegers(list<integer> integers) {     int[] ret = new int[integers.size()];     iterator<integer> iterator = integers.iterator();     (int = 0; < ret.length; i++)     {         ret[i] = iterator.next().intvalue();     }     return ret; } 

Comments

Popular posts from this blog

linux - Does gcc have any options to add version info in ELF binary file? -

javascript - Clean way to programmatically use CSS transitions from JS? -

android - send complex objects as post php java -