3

GWTで動的な数のラジオボタンを作成しています

      public void createTestList(ArrayList<Test> result){
    for(int i =0 ; i<result.size();i++){
                    int id = result.get(i).getTestId();
        RadioButton rd = new RadioButton("group", result.get(i).getTestType());
        verticalPanel.add(rd);
    }

Test は私のエンティティクラスです..

ビューで 4 つの異なるタイプのラジオ ボタンを取得しています。ラジオ ボタンのいずれかを選択すると、最初に選択したラジオ ボタンの ID を取得する必要があります。

第二に、複数のラジオボタンのどれが選択されているかを確認するにはどうすればよいですか?

ありがとう

4

2 に答える 2

2

チェックされているかどうかにかかわらず、各ラジオ ボタンで public java.lang.Boolean getValue() をチェックする必要があります。

于 2012-05-24T06:08:58.920 に答える
0

クリック ハンドラーを追加し、選択したラジオ ボタン変数を更新することができます。

choiceItemKind = new VerticalPanel();
ArrayList<String> kinds = new ArrayList<String>();
kinds.add(...);
kinds.add(...);

choiceItemKind.clear();

ClickHandler choiceClickHandler = new ClickHandler()
{
    @Override
    public void onClick(ClickEvent event)
    {
        addItemKindSelectedLabel = ((RadioButton) event.getSource()).getText();
    }
};

for (String label : kinds)
{
    RadioButton radioButton = new RadioButton("kind", label);
    //radioButton.setTitle("Tooltyp");
    if (label.equals(addItemKindSelectedLabel))
        radioButton.setValue(true);
    radioButton.addClickHandler(choiceClickHandler);
    choiceItemKind.add(radioButton);
}
...
addItemKindSelectedLabel = "";
...
if (!addItemKindSelectedLabel.isEmpty())
    ...;

upd: 選択したラジオボタンを再構築せずに設定:

for (int i = 0; i < choiceItemKind.getWidgetCount(); i++)
{
    RadioButton radioButton = (RadioButton) choiceItemKind.getWidget(i);
    radioButton.setValue(radioButton.getText().equals(addItemKindSelectedLabel));
}
于 2015-05-13T08:12:41.627 に答える