在Codenameone中有一种方法可以检测表中的单元格何时被单击,这样我就可以找出用户选择了什么?我在单元格上寻找像addActionListener这样的东西,却找不到一个,还有别的吗?
答案 0 :(得分:1)
假设表格不可编辑(在可编辑的表格中,单元格是文本字段),这应该很简单:
Form hi = new Form("Table", new BorderLayout());
Table clickTable = new Table(new DefaultTableModel(new String[]{"AAA", "BBB"}, new String[][] {
{"Row 1 A", "Row 1 B"},
{"Row 2 A", "Row 2 B"},
{"Row 3 A", "Row 3 B"},
})) {
@Override
protected Component createCell(Object value, int row, int column, boolean editable) {
if(editable) {
return super.createCell(value, row, column, editable);
}
Button b = new Button("" + value);
b.addActionListener(e -> ToastBar.showMessage("Clicked " + row + ", " + column, FontImage.MATERIAL_INFO));
return b;
}
};
hi.add(BorderLayout.CENTER, clickTable);
hi.show();