1

有点像刽子手

如果其中有东西,如何跳过图像视图并检查其中是否有东西尝试检查图像视图中是否有图像

代码

     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);


        }
  });
  }

基本上我想检查 ImageView 以查看 imageview 17 中的图像是否存在,如果是,则跳过 17 并将 imageresource 6 添加到 imageview18

我还想确保当我在单击图像视图 17 时将相同的代码添加到 7 或 8 的图像视图 6 时,如果我为另一个图像视图 17 执行此操作不会搞砸

我该如何解决这个问题?

4

3 回答 3

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

}

的文档getDrawable说:

返回视图的可绘制对象,如果未分配可绘制对象,则返回 null。

于 2013-05-08T15:56:32.633 回答
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.

于 2013-05-08T15:57:24.427 回答
0

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

于 2013-05-08T15:57:22.193 回答