0
我想在CellList組件中選擇多個單元; 我是GWT新手,有人請幫忙。 爲了獲得多選,我如何修改下面的代碼?需要GWT中的多選CellList
public class HelloWorld implements EntryPoint {
private static final List<String> DAYS = Arrays.asList("Sunday", "Monday", "Tuesday", "Wednesday", "Thursday",
"Friday", "Saturday");
public void onModuleLoad() {
// Create a cell to render each value.
TextCell textCell = new TextCell();
// Create a CellList that uses the cell.
CellList<String> cellList = new CellList<String>(textCell);
cellList.setKeyboardSelectionPolicy(KeyboardSelectionPolicy.ENABLED);
// Add a selection model to handle user selection.
final SingleSelectionModel<String> selectionModel = new SingleSelectionModel<String>();
cellList.setSelectionModel(selectionModel);
selectionModel.addSelectionChangeHandler(new SelectionChangeEvent.Handler() {
public void onSelectionChange(SelectionChangeEvent event) {
String selected = selectionModel.getSelectedObject();
if (selected != null) {
// Window.alert("You selected: " + selected);
}
}
});
cellList.setRowCount(DAYS.size(), true);
// Push the data into the widget.
cellList.setRowData(0, DAYS);
// Add it to the root panel.
RootPanel.get("gwtCellListBox").add(cellList);
}
}
嗨,我試着用下面的代碼進行多重選擇,它可以很好地用_ ** Ctrl ** _鍵按住。但是我想使用_ **進行這種多重選擇,而不需要按住_ ** Ctrl ** _ –
final MultiSelectionModel selectModel = new MultiSelectionModel (); \t \t cellList.setSelectionModel(selectModel); \t \t selectModel.addSelectionChangeHandler(新SelectionChangeEvent.Handler(){ \t \t \t公共無效onSelectionChange(SelectionChangeEvent事件){ \t \t \t \t設置選擇= selectModel.getSelectedSet(); \t \t \t \t如果(選擇! = NULL){ \t \t \t \t \t //Window.alert("You選擇:「+選擇); \t \t \t \t} \t \t \t} \t \t}); –
我建議你爲多個選擇添加一個複選框列,如果你需要幫助,請告訴我。 –