整数の配列を、独自に作成したイメージビューのタグと比較しようとしています。
この行を使用して:
if(grid[i][j] == buttons[k].getTag()){
私は正しい軌道に乗っていることを知っていますが、キャストする必要があるのか 、メソッドを使用する必要があるのか わかりません。簡単な質問だと思いますが、どんな助けでも大歓迎です、ありがとう。
タグはオブジェクトなので、次のように入力しInteger
ます:
/*
* UseValueOf
* ----------
* Priority: 4 / 10
* Severity: Warning
* Category: Performance
*
* You should not call the constructor for wrapper classes directly, such as`new
* Integer(42)`. Instead, call the valueOf factory method, such as
* Integer.valueOf(42). This will typically use less memory because common
* integers such as 0 and 1 will share a single instance.
*/
//MyView.setTag(new Integer(42));
MyView.setTag(Integer.valueOf(42));
次に、次のように値を取得します。
int tagValue = (Integer)MyView.getTag();
buttons[k].getTag() を整数に変換する必要があります。
これを行う:
if(grid[i][j] == Integer.parseInt(buttons[k].getTag().toString())){
あなたのタグは整数ではなく文字列だと思います。
その場合は、Integer を String() に変換し、equals() かどうかを確認します。