1

Kinda like hangman

how to skip over the imageview if something is in it and check to see if something is in it trying to check the imageView if there is an image in it

CODE

     final boolean imageThere = mImageView17.setBackgroundResource(null);
      public void image6(){
      randomNumber();
      final int thisLetter = currentLetter;
      final boolean imageThere = mImageView17.setBackgroundResource(null);

      mImageView6 = (ImageView) findViewById(R.id.imageView6);
      mImageView6.setImageResource(thisLetter);       
      mImageView6.bringToFront();

     mImageView17 = (ImageView)findViewById(R.id.imageView17);
      mImageView6.setOnClickListener(new OnClickListener() {

        public void onClick(View v) {
            // TODO Auto-generated method stub
            if (imageThere == false) {
            mImageView17.setImageResource(thisLetter);
            mImageView17.bringToFront();
            mImageView6.setImageResource(R.drawable.whitespace);
            } else {
                mImageView18.setImageResource(thisLetter);
                mImageView18.bringToFront();
                mImageView6.setImageResource(R.drawable.whitespace);    

            }

            }



  });

     mImageView17.setOnClickListener(new OnClickListener() {
          public void onClick(View v) {
            // TODO Auto-generated method stub
            mImageView6.setImageResource(thisLetter);
            mImageView6.bringToFront();
            mImageView17.setImageResource(R.drawable.whitespace);


        }
  });
  }

Basically I want to check the ImageView to see if the image in imageview 17 is there, If it is, Skip over 17 and add imageresource 6 to imageview18

I also want to make sure that if I do this for another imageview17 does not get messed up when I add the same code to imageview 6 of 7 or 8 when I click on image view 17

How do I go about fixing this?

matzone
  • 5,703
  • 3
  • 17
  • 20
baron dune
  • 387
  • 1
  • 5
  • 23

3 Answers3

4
if (mImageView17.getDrawable() != null) {
  // I already have a bitmap

}

the doc for getDrawable says:

Return the view's drawable, or null if no drawable has been assigned.

Blackbelt
  • 156,034
  • 29
  • 297
  • 305
2

I think you'd be better off storing your game state in some other Variables / Objects that are designed specifically to store that information, rather than relying on your UI to store the gamestate for you.

So for instance if the user gets 18 guesses you could store an int that represents how many times the user has guessed. And then based on that int you will make a decision on how to update the UI(which image view to set the image in). I don't know the exact mechanics of your game, so I may have overspimplified it, but the overall approach of storing your game state in some Object should be possible no matter what your game mechanics are.

This way you always have access to your game state anything you may need it for, and you can use that int to update the UI accordingly as play continues.

FoamyGuy
  • 46,603
  • 18
  • 125
  • 156
  • can you send me a link on how to do that, im kinda new at this stuff. so any type of info would help – baron dune May 08 '13 at 16:09
  • not given only the information that I know, I'd have to know more about your specific game to be able to offer anything more specific than the general idea that I've already put in my answer. – FoamyGuy May 08 '13 at 18:13
0

You can use getDrawable() for it to check whether the drawable has been set already. Check for every imageview and continue looping. Source.

Kanth
  • 6,681
  • 3
  • 29
  • 41