一、场景
点击Button后弹出多个选项,用户选中其中一个选项后将选项内容显示到Button上。
二、实现效果
三、代码
schoolYear = (Button) findComponentById(ResourceTable.Id_school_year);
schoolYear.setClickedListener(component -> {
ListDialog listDialog = new ListDialog(this);
String []items = {"2024-2025", "2023-2024", "2022-2023", "2021-2022", "2020-2021",
"2019-2020", "2018-2019"};
listDialog.setItems(items);
listDialog.setTitleText("请选择学年:");
listDialog.setAlignment(LayoutAlignment.CENTER);
listDialog.setOnSingleSelectListener((iDialog, i) -> {
schoolYear.setText(items[i]);
listDialog.destroy();
});
listDialog.show();
});