vendredi 15 avril 2016

show Random display of dice image from drawable folder in Android while adding it's value

To make my question clear, I have these dice images range from 1 to 4 which is imported on the drawable folder. What am trying to do is during the app's run on the emulator, the dices would show its original look:

ex.

figure 1: [.] -image of dice one [..] - image of dice two

underneath these two is a button named play so when the user click this button, the images for these dices will now be randomly changed.

figure 2: [...] -from dice one to three [....] - from dice two to four

It may sound simple by using setimageresource aside from it randomly changes, I need to add its value.

for example,

[.] - In my figure 1 above: dice one has originally a value of one. But when it suddenly changes to dice three in Figure 2 above, it now has the image of dice three and also a value of number 3.

same with dice two in my figure 1 above:

[..] it has a value of two, but when it changes to dice image 4, it now has an value of 4.

So 3+4=7. When the user clicks the play button not only the images randomly display new images of dice but it also adds its value and determine which number is the highest. In this example, 4 is the highest right? So this is only the time that the app would say who's the winner by a pop-up.

toast.makeText(this,"You Win!",Toast.LENGTH_LONG).Show();

Below is my code in trying to do it:

dice1=setImageResource(R.drawable.dice2s); but this won't make the dice image display randomly.

Could you help me? Am sorry for my limited english. This one is quite hard to explain though. But I hope you do get my point. I really need somebody who can read behind Android codes and I hope its one of you.

Thanks in advance.




Aucun commentaire:

Enregistrer un commentaire