• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

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

 
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
You totally ruined the moon. You're gonna hafta pay for that you know. This tiny ad agrees:
a bit of art, as a gift, the permaculture playing cards
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic