我知道我做错了什么,但我真的不知道它是什么,我想要完成的是让 switch 语句知道一个 ImageView 是否消失了,然后让我知道一个已经消失。如果两个图像视图消失,则移至第 2 号,然后移至第 3 号。它适用于第一个,但如果在此处编写此代码,则不会移动两个第二个
工作代码
if (numOne == ImageView.GONE) {
Toast.makeText(.......).show()
}
if (numTwo == ImageView.GONE + 2) {
Toast.makeText(.......).show()
}
我知道如果第一个语句为真,它不会流经 if 语句,这就是为什么我需要一个 switch 语句以便它通过所有语句
这是我的开关声明 ** 编辑的开关声明
public void checkIfCorrect() {
//checking the game to see if the numbers are correct
int numOne = ImageView.GONE;
int numTwo = ImageView.GONE + 2;
int numThree = ImageView.GONE + 3;
int numFour = ImageView.GONE + 4;
int numFive = ImageView.GONE + 5;
int numSix = ImageView.GONE + 6;
int numSeven = ImageView.GONE + 7;
int numEight = ImageView.GONE + 8;
int numNine = ImageView.GONE + 9;
int numTen = ImageView.GONE + 10;
switch (iGone = 0){ //tried using switch (ImageView.GONE) didn't work
case 1:
if (numOne == ImageView.GONE) {
Toast.makeText(this, "One Gone Now Put two in the basket", Toast.LENGTH_LONG).show();
};
break;
case 2:
if (numTwo == ImageView.GONE + 2){
Toast.makeText(this, "Two Gone Now Put Three in the basket", Toast.LENGTH_LONG).show();
};
break;
case 3:
if (numThree == ImageView.GONE + 3) {
Toast.makeText(this, "Three Gone Now Put Four in the basket", Toast.LENGTH_LONG).show();
}
break;
case 4:
if (numFour == ImageView.GONE + 4){
Toast.makeText(this, "Four Gone Now Put Five in the basket", Toast.LENGTH_LONG).show();
}
break;
case 5:
if (numFive == ImageView.GONE + 5) {
Toast.makeText(this, "Five Gone Now Put two in the basket", Toast.LENGTH_LONG).show();
}
break;
}
我要再次尝试完成的是,当一个 ImageView 消失时,让我知道并告诉我一个消失了,然后从 0 开始移动两个并数到两个,然后一旦你完成第二个从 0 开始并计数3等……
编辑我想做什么
所以我想要做的是计数到 10。通过删除 imageview 来做到这一点,当 imageview 到达某个位置时,它将被删除,我想要上面发布的这段代码来检查删除了多少 imageView,说如果 0在第 1 号被删除,如果在第 2 号删除 1 个图像视图,等等......请让我知道如何让它更清楚
回答大家的问题
出于某种原因,它不允许我在每个人下面发表评论,比如我有限制或其他什么,所以我要多解释一点@Shiva,我只希望它在第一个案例完成后转到第一个案例,也许如果我添加这个它会帮助大家理解
我的一个 imageViews 的代码
public boolean onTouch(View v, MotionEvent event) {
int x = (int)event.getX();
int y = (int)event.getY();
switch(event.getActionMasked()) {
//touch down so check if finger is on ball
case MotionEvent.ACTION_DOWN:
//
break;
case MotionEvent.ACTION_MOVE:
//moves the image with the finger
if (mImageView16.getX() > 0 && mImageView16.getY() >0) {
mImageView16.setX(x + mImageView16.getX());
mImageView16.setY(y + mImageView16.getY());
}// color square 50 50
if (mImageView16.getX() >= 430 && mImageView16.getX()<= 470 && mImageView16.getY() >= 80 && mImageView16.getY() <= 120) { //colorsquare RGBY
mImageView16.setVisibility(gone);
} else {
}
break;
case MotionEvent.ACTION_UP:
// touch drop will do things here after drop
checkIfCorrect();
}
return true;
}
}); // one more bracket then end of class
} // end of class
现在我在删除 ImageView 后调用检查是否正确,现在当我调用检查是否正确时,我想知道类检查是否正确以及它们的编号是否正确。如果他们在第一个数字 1 上,则数到第一。如果他们在第 2 位,那么从 0 个 imageviews 开始计数到第 2 位,我希望这可以解决问题。
@nachokk 不会使 iGone 成为布尔值,因此使其与 switch 语句不兼容吗?我再次知道这应该是评论,但我的评论不起作用?
好的,由于某种原因,IE 10 上没有通过评论
现在我添加了这个,它通过从 1 到 5 的 case 语句递增
好的,所以我能够找到我需要的答案的解决方案,我需要在完成命令时遍历每个 case 语句,这就是它的完成方式
代码
public void checkIfCorrect() {
//checking the game to see if the words are correct
//counting my numbers and image views gone
int numOne = ImageView.GONE;
int numTwo = ImageView.GONE + 2;
int numThree = ImageView.GONE + 3;
int numFour = ImageView.GONE + 4;
int numFive = ImageView.GONE + 5;
int numSix = ImageView.GONE + 6;
int numSeven = ImageView.GONE + 7;
int numEight = ImageView.GONE + 8;
int numNine = ImageView.GONE + 9;
int numTen = ImageView.GONE + 10;
switch (iGone++){
case 0:
if (numOne == ImageView.GONE) {
Toast.makeText(this, "One Gone Now Put one more to get to 2", Toast.LENGTH_LONG).show();
iGone = 1;
}
break;
case 1:
if (numTwo == ImageView.GONE + 2){
Toast.makeText(this, "Two Gone Now Put Three in the basket", Toast.LENGTH_LONG).show();
iGone = 2;
}
break;
case 2:
if (numThree == ImageView.GONE + 3) {
Toast.makeText(this, "Three Gone Now Put Four in the basket", Toast.LENGTH_LONG).show();
iGone = 3;
}
break;
case 3:
if (numFour == ImageView.GONE + 4){
Toast.makeText(this, "Four Gone Now Put Five in the basket", Toast.LENGTH_LONG).show();
iGone = 4;
}
break;
case 4:
if (numFive == ImageView.GONE + 5) {
Toast.makeText(this, "Five Gone Now Put two in the basket", Toast.LENGTH_LONG).show();
iGone = 5;
}
break;
但是我试图完成的事情并没有解决
为了更好地解决我的问题,我试图将 iGone 的值设置为 = case 语句中的一个案例。我希望 iGone 每次 ImageView.getVisibility == 消失时增加 1;Gone 是一个 ='s ImageView.GONE; 的变量。这是例如代码
**gone code**
gone = ImageView.GONE;
现在为了让事情更清楚,每个图像都是一个类 image5(),image6(),.... 最多 16 个,除了它们与哪个 imageview 相等的变量之外,所有类都完全相同。
现在如果你看上面你会看到 image16() 的触摸类,(mImageView16)
当它到达 setX 和 setY 坐标时,我如何使它 = iGone + 1 这是我尝试过的
在每个图像类上都试过这个
public boolean onTouch(View v, MotionEvent event) {
int x = (int)event.getX();
int y = (int)event.getY();
switch(event.getActionMasked()) {
//touch down so check if finger is on ball
case MotionEvent.ACTION_DOWN:
//
break;
case MotionEvent.ACTION_MOVE:
//moves the image with the finger
if (mImageView5.getX() > 0 && mImageView5.getY() > 0) {
mImageView5.setX(x + mImageView5.getX());
mImageView5.setY(y + mImageView5.getY());
} //color square 1
if (mImageView5.getX() >= 430 && mImageView5.getX()<= 470 && mImageView5.getY() >= 80 && mImageView5.getY() <= 120) { //colorsquare RGBY
mImageView5.setVisibility(gone);
}
if (mImageView5.getVisibility() == gone) { //colorsquare RGBY
++iGone; //HERE IS WHERE I TRIED IT
//I have also tried iGone = iGone + 1; and iGone++; nothing works
}
break;
case MotionEvent.ACTION_UP:
// touch drop will do things here after drop
checkIfCorrect();
}
return true;
}
});
出于某种原因,iGone =sa 每次我知道这一点时都不同,因为我在 checkifcorrect 类中调用了一个 toast 语句,该类是带有 switch 语句的类
检查类是否正确
public void checkIfCorrect() {
//checking the game to see if the words are correct
switch (iGone){
case 1:
Toast.makeText(this, "One Gone Now Put one more to get to 2", Toast.LENGTH_LONG).show();
break;
case 2:
Toast.makeText(this, "Two Gone Now Put Three in the basket", Toast.LENGTH_LONG).show();
break;
case 3:
Toast.makeText(this, "Three Gone Now Put Four in the basket", Toast.LENGTH_LONG).show();
break;
case 4:
Toast.makeText(this, "Four Gone Now Put Five in the basket", Toast.LENGTH_LONG).show();
break;
case 5:
Toast.makeText(this, "Five Gone Now Put two in the basket", Toast.LENGTH_LONG).show();
break;
}
Toast.makeText(this, "The amount is" + iGone + "Yeah", Toast.LENGTH_LONG).show();
}
我非常困惑为什么 iGone 每次都保留 = 不同的数字。
好的,所以现在的主要问题是。如何让 iGone 等于消失的图像视图数量,以便它可以调用正确的 switch case 语句?