Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Manually trigger Pull to refresh on Container

Tags:

codenameone

If I want to manually trigger Pull to Refresh on Container in Codename One after the load of the form. Please advise if anyone have any idea.

like image 212
Vinod Avatar asked Jul 05 '18 03:07

Vinod


1 Answers

It's easy, the trick is the use of the showListener. Suppose that this is the starting code (taken from the Codename One Developer Guide, section "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();

To invoke the "Pull to Refresh" listener after the load of the Form, you can do so:

    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();
like image 74
Francesco Galgani Avatar answered Nov 16 '22 04:11

Francesco Galgani