当我从数组创建表时,我在第一列填充数组中存在的值,第二列是ckeckBoxes,其中包含数组索引的值。我需要检索所选复选框的名称。以下是我的代码,有人可以帮我吗?
感谢您的帮助!
public class AddDoodlePart3 extends Composite {
MainView main = new MainView();
FlexTable table= new FlexTable();
VerticalPanel ab = new VerticalPanel();
HorizontalPanel hor = new HorizontalPanel();
InlineLabel lb = new InlineLabel("tette");
CheckBox ck ;
TextBox orario = new TextBox();
Button btn = new Button("Inserisci");
int culo;
public AddDoodlePart3(String det, ArrayList<String> listDate){
initWidget(this.ab);
this.ab.add(lb);
System.out.println(det+listDate.size());
table.setText(0, 0, " ");
table.setText(0, 1, "Opzione");
table.setText(0, 2, " ");
System.out.println("1");
for(int i=0;i<listDate.size();i++){
System.out.println(i);
this.ck = new CheckBox(""+i);
table.setWidget(i, 0, ck);
table.setText(i, 1, listDate.get(i));
ck.addClickHandler(new ClickHandler() {
@Override
public void onClick(ClickEvent event) {
boolean checked = ((CheckBox) event.getSource()).getValue();
Window.alert("It is " + (checked ? "" : "not ") + "checked "+ culo);
}
});
}
this.ab.add(table);
this.hor.add(orario);
this.hor.add(btn);
this.ab.add(hor);
btn.addClickHandler(new ClickHandler() {
@Override
public void onClick(ClickEvent event) {
// System.out.println(culo);
}
});
}
}
答案 0 :(得分:0)
您应该将DataGrid小部件用于这些目的。有关示例,请参阅GWT Showcase。单击“源代码”链接以查看如何实现此DataGrid。
您可以在DataGrid上设置SelectionModel - 在您需要MultiSelectionModel的情况下。然后,获取所选项目列表就像以下一样简单:
selectionModel.getSelectedSet();