jeudi 25 juin 2020

Questions about image random

Hello I am a beginner learning Java I am trying to create a random image output The code I made stops with only one image coming out What I want is to keep showing the images at random Which code should I add? Please help me

protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);


        ImageView imageView_1 = findViewById(R.id.imageView_1);
      

        int[] images = {R.drawable.img_1, R.drawable.img_2, R.drawable.img_3, R.drawable.img_4, R.drawable.img_5};

            Random rand = new Random();

            imageView_1.setImageResource(images[rand.nextInt(images.length)]);
        
        }
}



Aucun commentaire:

Enregistrer un commentaire