PDA

View Full Version : How can I do this..???? Help please...




bytezone
May 6, 2009, 09:03 AM
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
May 6, 2009, 11:37 AM
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
May 6, 2009, 12:28 PM
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...!!!