• Post Reply Bookmark Topic Watch Topic
  • New Topic

Android: Random Images Shown in image view linked to matching buttons  RSS feed

 
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi so I am currently messing about with android/Java code. The little program I am working on randomly selects and displays an image. This works perfectly but now what I want to do is link certain images to a button.

For example if a picture of a cat is displayed from the drawable then pressing the cat button would then pick the next random image from the drawbable and like wise if a image of a dog then the dog button would be the only correct input. If the wrong button was pressed the program would go to a game over screen.

Currently I have setup the code so on start a random image if shown and upon pressing a button no matter what the image is it will load the next. Here parts of the code I have used so far:




Images in the drawable are stored as dog1,dog2,dog3.... cat1,cat2 and so on. Can any one help why the code isn't working? When I press the buttons with the if statements it crashes the app whether it is hte correct or incorrect image on the screen. From what I can work out the code is having trouble reading what is in the string to check if it starts with cat or dog.
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!