teratail header banner
teratail header banner
質問するログイン新規登録

回答編集履歴

1

ミスの修正

2016/07/05 12:31

投稿

intelf___
intelf___

スコア868

answer CHANGED
@@ -12,12 +12,12 @@
12
12
  まとめて扱ったり分けて扱ったりしているので予め構造体のようなクラスを宣言するとよさそうですね。
13
13
  ```java
14
14
  class Toi{
15
- String que;
15
+ String que;
16
- RadioButton[] radio;
16
+ RadioButton[] radio;
17
- Toi(String ans, RadioButton radio){
17
+ Toi(String que, RadioButton[] radio){
18
- this.ans = ans;
18
+ this.que = que;
19
- this.radio = radio;
19
+ this.radio = radio;
20
- }
20
+ }
21
21
  }
22
22
  ```
23
23
  こんな感じのクラス。
@@ -35,17 +35,17 @@
35
35
  RadioButton[][] radio = new RadioButton[ANSWRE.length][ANSWRE[0].length];
36
36
  //ラジオボタン設定
37
37
  for(int n = 0; n < ANSWRE.length; n++){
38
- for(int m = 0; m < ANSWRE[n].length; m++){
38
+ for(int m = 0; m < ANSWRE[n].length; m++){
39
- radio[n][m] = new RadioButton(this);
39
+ radio[n][m] = new RadioButton(this);
40
- radio[n][m].setText(ANSWRE[n][m]);
40
+ radio[n][m].setText(ANSWRE[n][m]);
41
- //idの設定とかもここで
41
+ //idの設定とかもここで
42
- }
42
+ }
43
43
  }
44
44
 
45
45
  //Toiクラス利用
46
46
  Toi[] toi = new Toi[QUESTION.length];
47
47
  for(int n = 0; n < toi.length; n++)
48
- toi[n] = new Toi(QUESTION[n], radio[n]);
48
+ toi[n] = new Toi(QUESTION[n], radio[n]);
49
49
  ```
50
50
 
51
51
  ここからシャッフルをします。
@@ -57,14 +57,14 @@
57
57
  List<Toi> list1 = Arrays.asList(toi.clone());
58
58
  Collections.shuffle(list1);//toiをシャッフルしたList型 list1
59
59
  for(Toi t: list1){
60
- List<RadioButton[]> list2 = Arrays.asList(t.ans.clone());
60
+ List<RadioButton> list2 = Arrays.asList(t.radio.clone());
61
- Collections.shuffle(list2);//シャッフル
61
+ Collections.shuffle(list2);//シャッフル
62
- t.ans = list2.toArray(new RadioButton[]{});//元に戻す
62
+ t.radio = list2.toArray(new RadioButton[]{});//元に戻す
63
63
  }
64
64
  ```
65
65
  のようになるかと。
66
- list1.que = 問題の文字
66
+ list1.get(0).que = 問題の文字
67
- list1.ans = ラジオボタンの配列
67
+ list1.get(0).radio = ラジオボタンの配列
68
68
  で取り出せます。
69
69
 
70
70
  こちらに実行環境がないのでミスがあると思います。参考までに。