次のように、3 つのウィジェットを複合ウィジェットにグループ化することをお勧めします。
class AnswerComposite extends Composite {
private final Label label;
private final TextBox textBox;
private final RadioButton radioButton;
public AnswerComposite() {
label = new Label("Answer:");
textBox = new TextBox();
radioButton = new RadioButton("answerGroup");
HorizontalPanel contentPanel = new HorizontalPanel();
contentPanel.add(label);
contentPanel.add(textBox);
contentPanel.add(radioButton);
initWidget(contentPanel);
}
public String getText() {
return textBox.getValue();
}
public boolean isSelected() {
return radioButton.getValue();
}
}
次に、それらをパネルに追加したり、次のようにリストに配置したりできます。
VerticalPanel answersPanel = new VerticalPanel();
List<AnswerComposite> answerComposites = new ArrayList<AnswerComposite>();
for (int i = 0; i < getLoopCount(); i++) {
AnswerComposite answerComposite = new AnswerComposite();
answersPanel.add(answerComposite);
answerComposites.add(answersComposite);
}
ウィジェットのチェックは非常に簡単になります。
answerComposites.get(i).getText();
answerComposites.get(i).isSelected();
ValueChangeHandler
aをsに追加することもおそらく便利RadioButton
です(enryboの回答を参照)。