我知道我做錯了什麼,但我真的不知道它是什麼,我想要完成的是switch語句知道如果一個ImageView不見了,然後讓我知道一個人走了。如果兩個圖像視圖消失,則移至數字2,然後移至數字3。它的工作原理與一個號碼,但沒有提出兩項二號如果寫到這裏變量不會增加一個等於正確的開關大小寫方法
此代碼工作代碼
if (numOne == ImageView.GONE) {
Toast.makeText(.......).show()
}
if (numTwo == ImageView.GONE + 2) {
Toast.makeText(.......).show()
}
據我所知,它不會流過if語句,如果第一個說法是正確的,這就是爲什麼我需要一個switch語句,因此經過他們都
這裏是我的SWITCH STATEMENT ** EDITED SWITCH STATEMENT
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號ECT ......
修改的內容IM試圖做
那麼什麼,我試圖做的是數到10.這樣通過去除imageviews,當ImageView的命中一個特定的位置它將被刪除,我想要這個代碼,我張貼上面檢查有多少imageViews被刪除,說如果0被刪除即時消息在1號,如果1圖像視圖被刪除即時在2號等等... ....請讓我知道如何使它更加清晰
回答大家的問題
出於某種原因,它不會讓下面大家我的評論像我有一個限制或東西,所以我要去解釋這一點更 @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個圖像開始算到2號,我希望這可以解決問題。
@nachokk不會使iGone成爲布爾值,因此使它與switch語句不兼容?再次我知道這應該是一個評論,但我的意見不工作?
確定由於某些原因10
現在我加入這一點,它增加通過case語句會從1至5
評論不會通過IE瀏覽器行,所以我能夠找到的決議我需要答案,我在完成命令時,需要通過每個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;
但即時通訊試圖acomplish不解決
爲了更好地解決我的問題,我試圖讓iGone的值= case case語句中。我希望iGone在每次ImageView.getVisibility ==消失時增加1;去了='s ImageView.GONE;這裏是例如
**gone code**
gone = ImageView.GONE;
現在做的事情每個圖像更清晰的代碼是一類圖像5(),image6(),......多達16個的所有類是完全除變量相同它們的圖像視圖相等。
現在如果你看看上面你會看到image16觸摸類(),(mImageView16)
如何,當它擊中的setX的和SETY cordinates我讓它= 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類中舉杯言這是W級第i個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與圖像瀏覽量保持一致,以便它可以調用正確的開關盒語句?
聽起來像你想要的遞歸方法。所以如果你的方法在你的Toast.makeText之後被稱爲toastVisibility(),你會想再次調用toastVisibility()。 –
即時閱讀遞歸現在,但我想要記錄ImageViews.GONE的數量,所以如果一個ImageView.Gone是完成它結束case語句之一,然後移動到第二個case語句不重複第一個。所以根據第一個case語句之後的遞歸我想要做if(ImageView.GONE = 1){return 0;並移動到第二個案例聲明 –
測試意見 –