2

このコードブロックで問題が発生しています。それはいつも「あなたは美術館の外にいる、またはあなたの位置をもう一度確認する」トーストに行きます:/あなたは何が問題だと思いますか?コードは次のとおりです。

    x3 = x3 * -1; //for example is 187
    y3 = y3 * -1;//for example is 698

    ImageView img = (ImageView) findViewById(R.id.imageView1);

    if(((x3 <= 150) && (x3 >= 170)) && ((y3 <= 680) && (y3 >= 725))){
        img.setImageResource(R.drawable.map_1_full_lite);
        Toast.makeText(getBaseContext(), "You're currently on Section 1", Toast.LENGTH_LONG).show();
        currentSection = "sect_1";
    }else if(((x3 <= 170) && (x3 >= 195)) && ((y3 <= 690) && (y3 >= 715))){
        img.setImageResource(R.drawable.map_2_full_lite);
        Toast.makeText(getBaseContext(), "You're currently on Section 2", Toast.LENGTH_LONG).show(); //this suppost to be the output
        currentSection = "sect_2";
    }else if(((x3 <= 200) && (x3 >= 230)) && ((y3 <= 680) && (y3 >= 720))){
        img.setImageResource(R.drawable.map_3_full_lite);
        Toast.makeText(getBaseContext(), "You're currently on Section 3", Toast.LENGTH_LONG).show();
        currentSection = "sect_3";
    }else if(((x3 <= 190) && (x3 >= 220)) && ((y3 <= 675) && (y3 >= 710))){
        img.setImageResource(R.drawable.map_4_full_lite);
        Toast.makeText(getBaseContext(), "You're currently on Section 4", Toast.LENGTH_LONG).show();
        currentSection = "sect_4";
    }else if(((x3 <= 175) && (x3 >= 219)) && ((y3 <= 710) && (y3 >= 745))){
        img.setImageResource(R.drawable.map_5_full_lite);
        Toast.makeText(getBaseContext(), "You're currently on Section 5", Toast.LENGTH_LONG).show();
        currentSection = "sect_5";
    }else if(((x3 <= 155) && (x3 >= 165)) && ((y3 <= 715) && (y3 >= 735))){
        img.setImageResource(R.drawable.map_6_full_lite);
        Toast.makeText(getBaseContext(), "You're currently on Section 6", Toast.LENGTH_LONG).show();
        currentSection = "sect_6";
    }else{
        Toast.makeText(getBaseContext(), "You're outside of the museum or Check your postion again", Toast.LENGTH_LONG).show();
    }
4

3 に答える 3

4

不可能だよ

(x3 <= 150) && (x3 >= 170)

そのまま

(x3 <= 170) && (x3 >= 195)

x3は150以下および170以上であってはなりません。あなたはこのようなことを意図していたと思います

(150 <= x3) && (x3 <= 170)

(170 <= x3) && (x3 <= 195)
于 2013-01-28T08:43:24.527 に答える
1

それは、

(x3 <= 150) && (x3 >= 170)

決して真実になることはできません。

これですか?

(x3 <= 150) || (x3 >= 170)
于 2013-01-28T08:43:15.883 に答える
1

あなたは常にある条件を持っていますfalse。考慮してください:

((x3 <= 155) && (x3 >= 165)) && ((y3 <= 715) && (y3 >= 735))

&&演算子は、AND式全体が真になるためには、その演算子の両側の両方の条件が真でなければならないことを意味します。これで、条件の任意の値が falseであることを確認するのは難しくありません。したがって、条件が満たされることはありません。x3(x3 <= 155) && (x3 >= 165)

あなたのすべてのブランチにifはそのプロパティがあるため、最終的にはelseブランチが選択されます。

<=(以下>=) 演算子と (以上) 演算子が混在していると思います。たとえばx3、すべての値はある範囲内 (すなわち、部屋の境界座標) にある必要があります。前述のケースのように、x3おそらく範囲内にある必要があります(x3 >= 155) && (x3 <= 165)(逆演算子に注意してください)。

于 2013-01-28T08:46:49.963 に答える