arrays - How to set ImageView Looping while i only have limited images ? (Android) -


i have array drawable, array drawable have 4 images, , have more 4 imageview, how set image on imageview looping, , when looping reach more 4, want it's return first image, this:

  • imageview 1 first drawable
  • imageview 2 second drawable
  • imageview 3 third drawable
  • imageview 4 fourth drawable
  • imageview 5 first drawable
  • imageview 6 second drawable

and on..

how ? appreciate, thank you!

u can use % operator. returns remainder of division. example, if have 6 views , 4 images, can way:

imageview[] viewsarray = new imageview[6]; //init array findviewbyid()  for(int = 0; < viewsarray.length; ++i) {    viewsarray[i].setimagedrawable(imagesarray[i % 4]); // if index 5 % operator return 1.   }     

Comments

Popular posts from this blog

php - Wordpress website dashboard page or post editor content is not showing but front end data is showing properly -

How to get the ip address of VM and use it to configure SSH connection dynamically in Ansible -

javascript - Get parameter of GET request -