codenameone - 在 Container 上手动触发 Pull 刷新
问题描述
如果我想在表单加载后手动触发在 Codename One 中的 Container 上的 Pull to Refresh。请告知是否有人有任何想法。
解决方案
这很容易,诀窍是使用showListener
. 假设这是起始代码(取自 Codename One Developer Guide,“Pull to refresh”部分):
Form hi = new Form("Pull To Refresh", BoxLayout.y());
hi.getContentPane().addPullToRefresh(() -> {
hi.add("Pulled at " + L10NManager.getInstance().formatDateTimeShort(new Date()));
});
hi.show();
要在加载表单后调用“Pull to Refresh”侦听器,您可以这样做:
Form hi = new Form("Pull To Refresh", BoxLayout.y());
Runnable myRunnable = () -> {
hi.add("Pulled at " + L10NManager.getInstance().formatDateTimeShort(new Date()));
};
hi.getContentPane().addPullToRefresh(() -> {
myRunnable.run();
});
hi.addShowListener(l -> {
myRunnable.run();
});
hi.show();
推荐阅读
- javascript - 下一个服务器不断崩溃
- python - 与不为零的更近的邻居重复值,直到值改变
- python - python中的合并排序
- powershell - 用于检索 SharePoint Online 文档库大小的 PowerShell
- react-native - 使用 react-navigation 重定向用户时出现错误的 setstate()?
- django - 如何使用带有额外字段的 Django 模型集?
- python - 为什么在 for 循环中使用 PIL 的 Image.paste 时出现图像重叠问题?
- c++ - unordered_set 对的令人惊讶的行为
- jupyter-notebook - `jupyter notebook`和`jupyter server`有什么区别?
- arrow-functions - “this”在函数中起作用,但在箭头函数中起作用。我想不知道为什么