English 中文(简体)
GWT: 如何获得选中的 radio 按钮 s 值
原标题:GWT:how to get selected radio button s value
  • 时间:2012-05-24 06:00:47
  •  标签:
  • gwt

我在我的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);
    }

测试是我的实体类...

现在,如果我选择一个无线电按钮, 首先我需要获得所选无线电按钮的代号, 这怎么可能?

第二,我如何检查选择哪个多个无线电按钮?

谢谢 谢谢

问题回答

您需要检查 public java. lang. Boolean getValue () 的每个收音机按钮是否被检查 。

可能添加点击处理器并更新选中的 radio 按钮变量 :

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())
    ...;

d: 设置选定的无线按钮, 不重建 :

for (int i = 0; i < choiceItemKind.getWidgetCount(); i++)
{
    RadioButton radioButton = (RadioButton) choiceItemKind.getWidget(i);
    radioButton.setValue(radioButton.getText().equals(addItemKindSelectedLabel));
}




相关问题
Refresh the UI in gwt

I have created some custom composite widget, which listens to an events (in my case loginEvent). Once the event is caught the state of the widget changes so as the way it should look (in my case I ...

How to create a development/debug and production setup

I recently deployed inadvertently a debug version of our game typrX (typing races at www.typrx.com - try it it s fun). It was quickly corrected but I know it may happen again. After digging on ...

GWT error at runtime: ....style_0 is null

My code works fine in IE 8, but on firefox 3.5, the javascript fails to load. I used firebug to figure out why, and the error I get is (GWT detailed mode) My suspicion is that some style is not ...

GWT s hosted mode not working

I ve been stumped for a while trying to figure out why my GWT demo app isn t working in hosted mode so I went back and downloaded the Google Web Toolkit again, unzipped it and simply went to the ...

How to disable Google Visualizations Tool Tips?

Does anyone know how to disable the tool-tip boxes that popup when a Google Visualizations chart is clicked (Selected)? Following the sample code at Getting Started with Visualizations, the "...

GWT 2 CssResource how to

I have a GWT 1.7 application and I want to upgrade it to GWT 2 Milestone 2. The application uses 2 big external CSS files. In GWT 1.7 I had a public folder and put both the CSS files in the folder and ...

热门标签