首页 > 解决方案 > 在 Container 上手动触发 Pull 刷新

问题描述

如果我想在表单加载后手动触发在 Codename One 中的 Container 上的 Pull to Refresh。请告知是否有人有任何想法。

标签: codenameone

解决方案


这很容易,诀窍是使用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();

推荐阅读