开发者

Display 20 random images over UI screen at a time in Android

开发者 https://www.devze.com 2023-02-16 01:17 出处:网络
HI, 开发者_运维知识库I want to display 20 random images at a time over Activity screen in android. I\'m using this snippet:-

HI,

开发者_运维知识库I want to display 20 random images at a time over Activity screen in android. I'm using this snippet:-

ImageView imageArr[] = new ImageView[25];
    int id[]={  R.drawable.letter1,R.drawable.letter2,R.drawable.letter3,R.drawable.letter4,
                R.drawable.letter5,R.drawable.letter6,R.drawable.letter7,R.drawable.letter8,
                R.drawable.letter9,R.drawable.letter10,R.drawable.letter11,R.drawable.letter12,
                R.drawable.letter13,R.drawable.letter14,R.drawable.letter15,R.drawable.letter16,
                R.drawable.letter17,R.drawable.letter18,R.drawable.letter19,R.drawable.letter20};

    ArrayList<Integer> randomArr = new ArrayList<Integer>();
    for(int i=0; i<20;i++) { 
        randomArr.add(i); 
    }
    Collections.shuffle(randomArr);

    for(int i=0; i<20; i++){  
        //ImageView mImageplay = (ImageView)findViewById(R.id.image_play);
        imageArr[i]=(ImageView)findViewById(id[randomArr.get(i)]);
        //mImageplay.setImageResource(id[randomArr.get(i)]);
    }

Here I'm having 20 custom images of size 49x49 pixels(small sizes)in drawable folder which i want to dispaly over UI at a time in random fashion with no alignment.

The problem is in imageArr[i] is showing NULL value for all the 20 images,whereas "randomArr" is having the correct shuffled data.

Also, Is there any way to display it in randomized look in Layout Area as i was not able to find out solution for this.

I am struck in this and not able to resolve it. please help me out for this.

thanks in advance. -pk


Your array id[] contains R.drawable. values (id of Drawables in your app) instead of R.id. (id of your ImageViews in your layout).

Set the android:id attributes in your layout, and use them in your id[] array.

0

精彩评论

暂无评论...
验证码 换一张
取 消