3

私はこの質問をグーグルで検索しましたが、それに対する単純または具体的な十分な答えが見つかりません:経験豊富なプログラマーが私を助けてくれますか...?

dialog1 というカスタム ダイアログに 10 個のチェックボックスの配列があります。

public class DigitsActivity extends Activity {
...
CheckBox[] ckbDigits = new CheckBox[10];
...


public void SelectDigit1(){  // method which opens the custom dialog

Context context=DigitsActivity.this;
final Dialog dialog1 = new Dialog(context);
...
for (int k = 0; k <= 9; k++){
  ckbDigits[k] = (CheckBox) dialog1.findViewById(R.id.ckbDigits[k]);
}
...
}

行で複数のエラーが発生しています

ckbDigits[k] = ...

私も試しました:

ckbDigits[] = (CheckBox) dialog1.findViewById(R.id.ckbDigits[]);

しかし、それも機能しません...

チェックボックスの配列を宣言する方法を誰か教えてもらえますか?

ありがとう。

4

3 に答える 3

0
  1. have you called "setContentView" before trying to find the views?
  2. have you initialized the array of ids ?
  3. what's this : "R.id.ckbDigits[]" ?
  4. in any case , i would suggest naming the ids as something like "checkbox0" , "checkbox1" ,... , and then find them by using getIdentifier (like this) , in order to make the initialization of the ids easier . you could make it stop when it didn't find the id that it has searched for.
于 2012-05-25T23:35:44.320 に答える
-1

このように CheckBox の新しいベクトルを宣言する必要があります

例えば ​​:

public class Test{
   static int ckbDigits[]={id.ckbDigits0,id.ckbDigits1,id.ckbDigits2,id.ckbDigits3,
    id.ckbDigits4
    id.ckbDigits5,id.ckbDigits6,id.ckbDigits7,id.ckbDigits8,id.ckbDigits9};

}

コードでこのようなものを作成した後

for (int k = 0; k <= 9; k++){
  ckbDigits[k] = (CheckBox) dialog1.findViewById(Test.ckbDigits[k]);
}
于 2013-05-25T12:48:33.320 に答える