Become a MacRumors Supporter for $50/year with no ads, ability to filter front page stories, and private forums.

bytezone

macrumors member
Original poster
Apr 20, 2009
64
0
Can anyone tell me how I can do this..

I need to create 10+ buttons dynamicaly and link the image of button to randomly selected images from the list. Every time the application is refreshed, I would like to reasign the images randomly to each button, so that no button gets same image on every refresh. The images in the list is 6 in total but buttons are more than 10+. Also each button needs to be linked to a single action.

Can anyone give me suggestions or direct me to resource which could help me implement this...??

Thanks
 

BlackWolf

macrumors regular
Apr 9, 2009
244
0
could you please be more specific?

1) what do you mean by "each time the application is refreshed"?

2) "so that no button gets same image on every refresh" ... do you mean the same as before? because if you have 6 images but 10+ buttons, some buttons MUST have the same images

in any case this should be pretty simple. you create a for-loop, and for every loop you create a button. if you need to store the buttons you can do so in an array.
after that, you get a random entry of the array your images are in (google "random numbers in c" to find out how to create a random number, then you take that random number as the index of the image in the array. you, of course, have to make sure the random number doesn't exceed the number of items in your array) and use that image.
 

bytezone

macrumors member
Original poster
Apr 20, 2009
64
0
Thanks for the response.

could you please be more specific?

1) what do you mean by "each time the application is refreshed"?

I meant , the app will have a refresh button. Whenever refresh button is pressed, the images on each button should be different.

2) "so that no button gets same image on every refresh" ... do you mean the same as before? because if you have 6 images but 10+ buttons, some buttons MUST have the same images

Its ok if some get same images.

in any case this should be pretty simple. you create a for-loop, and for every loop you create a button. if you need to store the buttons you can do so in an array.
after that, you get a random entry of the array your images are in (google "random numbers in c" to find out how to create a random number, then you take that random number as the index of the image in the array. you, of course, have to make sure the random number doesn't exceed the number of items in your array) and use that image.

Thanks will try it out...!!!
 
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.