Manually trigger Pull to refresh on Container
Asked Answered
C

1

6

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.

Copyreader answered 5/7, 2018 at 3:56 Comment(0)
M
3

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();
Midge answered 5/7, 2018 at 8:40 Comment(3)
FYI if you are using InfiniteContainer you can use refresh().Hampton
Shai. refresh() method doesn't trigger manual refresh on the container. I want to refresh the container after the load of the form means I should trigger swipe down (refresh) action manually without swiping down the container. Please advise. ThanksCopyreader
pullToRefresh just invokes a method you can just invoke that method manually as shown by by @francesco-galganiHampton

© 2022 - 2024 — McMap. All rights reserved.