string picker width is 0

20 views
Skip to first unread message

howud...@gmail.com

unread,
Jul 24, 2016, 9:56:18 PM7/24/16
to CodenameOne Discussions
the string picker is showing with no width, so the items can't be chosen?
     Picker picker = new Picker();
    picker.setStrings("", "String 1", "String 2");
    TableLayout layout = new TableLayout(5,3);

        Container cnt1 = new Container(layout);
        cnt1.add(layout.createConstraint().widthPercentage(20), new Label());
        cnt1.add(layout.createConstraint().widthPercentage(40), new Label());
        cnt1.add(layout.createConstraint().widthPercentage(40), new Label());
    cnt1.add(layout.createConstraint().horizontalSpan(1), new Label("Last:"));
    cnt1.add(layout.createConstraint().horizontalSpan(1), new TextField());
    cnt1.add(layout.createConstraint().horizontalSpan(1),picker);



result:


Shai Almog

unread,
Jul 25, 2016, 12:04:11 AM7/25/16
to CodenameOne Discussions, howud...@gmail.com
Odd that it would do that. Use setRenderingPrototype("XXXXXXXXXXXX") to determine the width for the picker.

Notice that on device this should map to the native picker for most cases and it will behave differently.

howud...@gmail.com

unread,
Jul 25, 2016, 12:36:14 AM7/25/16
to CodenameOne Discussions, howud...@gmail.com
ok, that sort of worked.  I guess I'll have to go through all the entries, find the longest one and use that.   bummer :(

Shai Almog

unread,
Jul 25, 2016, 11:58:55 PM7/25/16
to CodenameOne Discussions, howud...@gmail.com
Just use a longer value than you are ever likely to have. FYI I've set a default prototype to the picker which makes sense so this should not behave like that in the coming update.

howud...@gmail.com

unread,
Jul 26, 2016, 1:22:59 AM7/26/16
to CodenameOne Discussions, howud...@gmail.com
thanks, will look forward to the update, for now I do:
    protected void setStrings (Picker picker, String[] strs) {
    picker.setStrings(strs);
    String sLongest = "";
    for (String s : strs)
    if (s.length() > sLongest.length())
    sLongest = s;
    picker.setRenderingPrototype(sLongest);
    }

Reply all
Reply to author
Forward
0 new messages