pull to refresh not working on tab component

77 views
Skip to first unread message

howud...@gmail.com

unread,
Jul 5, 2016, 10:28:05 PM7/5/16
to CodenameOne Discussions
tested in the simulator with the below code, pullToRefresh runnable is not getting called
        Form hi = new Form("Hi World");
        hi.setLayout(new BorderLayout());
         Tabs t = new Tabs();
    t.addTab("Test1", new com.codename1.ui.Label("Test1"));
    t.addTab("Test2", new com.codename1.ui.Label("Test2"));
    t.setScrollableY(true);
    t.addPullToRefresh(new Runnable() {
@Override
public void run() {
System.out.println("Tab Refresh");
}
    });

    hi.add(BorderLayout.CENTER, t);
hi.show();


I dont necessarily want the tab to be pull to refresh, but only the content of tab "Test1" which is actually a container.

Shai Almog

unread,
Jul 6, 2016, 1:38:37 AM7/6/16
to CodenameOne Discussions, howud...@gmail.com
You can't have the Tabs component itself scrollable. It won't look good.
You want to have the containers added to the tabs as the scrollable/refreshable elements.

howud...@gmail.com

unread,
Jul 6, 2016, 6:55:31 PM7/6/16
to CodenameOne Discussions, howud...@gmail.com
ok, I still cant seem to get this to work.  Here is my layout:
Form (FrmMain) -> Tabs -> Container (PnlCurrentActivity).  I set pull to refresh on PnlCurrentActivity, but the refresh event never fires

FrmMain:
public class FrmMain extends com.codename1.ui.Form {
protected PnlCurrentActivity pnlCurrentActivity = new PnlCurrentActivity();
    public FrmMain() {
        this(com.codename1.ui.util.Resources.getGlobalResources());
    }
    
    public FrmMain(com.codename1.ui.util.Resources resourceObjectInstance) {
        initGuiBuilderComponents(resourceObjectInstance);
        initManualComponents();
    }
    
//-- DON'T EDIT BELOW THIS LINE!!!


// <editor-fold defaultstate="collapsed" desc="Generated Code">                          
    private void initGuiBuilderComponents(com.codename1.ui.util.Resources resourceObjectInstance) {
        setLayout(new com.codename1.ui.layouts.BorderLayout());
        setTitle("Dashboard");
        setName("FrmMain");
    }// </editor-fold>

//-- DON'T EDIT ABOVE THIS LINE!!!
    protected void initManualComponents() {
    Tabs t = new Tabs();
    t.addTab("Current Activity", pnlCurrentActivity);
    t.addTab("Follow Up", new Label("Test");
    t.setScrollableY(true);
     this.add(BorderLayout.CENTER, t);
    }
}

PnlCurrentActivity:
public class PnlCurrentActivity extends com.codename1.ui.Container {
protected PnlCurrentActivity me = null;
    public PnlCurrentActivity() {
        this(com.codename1.ui.util.Resources.getGlobalResources());
    }
    
    public PnlCurrentActivity(com.codename1.ui.util.Resources resourceObjectInstance) {
        initManualComponents();
    }
    
    protected void initManualComponents() {
        this.setLayout(new BoxLayout(BoxLayout.Y_AXIS));
    this.addPullToRefresh(new Runnable() {
@Override
public void run() {
System.out.println("Pnl Refresh");
}
    });
        me = this;
        refresh();
    }

public void refresh() {
InfiniteProgressWithMessage prog = new InfiniteProgressWithMessage();
prog.showInifiniteBlocking();

prog.message.setText("Retrieving Current Activity");
loadCurrentActivity(prog);
}

protected void loadCurrentActivity(InfiniteProgressWithMessage prog) {
ConnectionRequest r = new ConnectionRequest() {
Vector<dbCurrentActivity> vData = new Vector<dbCurrentActivity>();

@SuppressWarnings({ "unchecked", "rawtypes" })
@Override
protected void readResponse(InputStream input) throws IOException {
ArrayList<Map<String, Object>> alCurrentActivity = (ArrayList)new JSONParser().parseJSON(new InputStreamReader(input)).get("activity");
for (Map<String,Object>entry : alCurrentActivity) {
vData.add(new dbCurrentActivity(entry));
}
}
@Override
protected void postResponse() {
for (dbCurrentActivity act : vData) {
       MultiButton mb = new MultiButton(act.getClient());
       mb.setHorizontalLayout(true);
       me.add(mb);
}
//display it
prog.dlg.dispose();
}
};
r.setUrl(GLOBALS.BASEURL + "/getCurrentActivity");
r.setPost(true);
NetworkManager.getInstance().addToQueueAndWait(r);
}
}

Shai Almog

unread,
Jul 7, 2016, 12:17:48 AM7/7/16
to CodenameOne Discussions, howud...@gmail.com
Remove this:

        t.setScrollableY(true);

The Tabs themselves should NOT be scrollable....

In PnlCurrentActivity use setScrollableY(true) because this component should be scrollable.
Reply all
Reply to author
Forward
0 new messages