Combobox codenameone选择器组合框的替代方案

Combobox codenameone选择器组合框的替代方案,combobox,codenameone,picker,Combobox,Codenameone,Picker,我的脚被Codename One弄湿了。我已经研究了更多的跨平台选择,如Xamarin,PhoneGap,Ionic,但我有点迷恋Codename one,因为它真的只需编写一次代码,就可以在任何地方运行 我一直在浏览ui元素,在填充组合框(另一种选择是选择器)时遇到了一些障碍 假设我将存储作为值对(storeId,storeName)。我想在Picker中显示storeName,但保留storeId作为值引用。 选择存储后,我希望将storeId传递给API调用。 这可能吗。这可能是一个非常简

我的脚被
Codename One
弄湿了。我已经研究了更多的跨平台选择,如
Xamarin
PhoneGap
Ionic
,但我有点迷恋
Codename one
,因为它真的只需编写一次代码,就可以在任何地方运行

我一直在浏览ui元素,在填充
组合框
(另一种选择是
选择器
)时遇到了一些障碍

假设我将存储作为值对(
storeId
storeName
)。我想在
Picker
中显示
storeName
,但保留
storeId
作为值引用。 选择存储后,我希望将
storeId
传递给API调用。
这可能吗。这可能是一个非常简单的问题,但似乎有点难以实现(我真的是移动新手)

谢谢。

我们的建议是。这是一种iOS本机上不存在的UI模式,在现代手机上会让人感到陌生。它存在于代号1中

在上面的示例代码中,您可以获得与复杂的多字段组合框类似的效果:

Form hi = new Form("Button", BoxLayout.y());

String[] characters = { "Tyrion Lannister", "Jaime Lannister", "Cersei Lannister"};
String[] actors = { "Peter Dinklage", "Nikolaj Coster-Waldau", "Lena Headey"};
int size = Display.getInstance().convertToPixels(7);
EncodedImage placeholder = EncodedImage.createFromImage(Image.createImage(size, size, 0xffcccccc), true);
Image[] pictures = {
    URLImage.createToStorage(placeholder, "tyrion","http://i.lv3.hbo.com/assets/images/series/game-of-thrones/character/s5/tyrion-lannister-512x512.jpg"),
    URLImage.createToStorage(placeholder, "jaime","http://i.lv3.hbo.com/assets/images/series/game-of-thrones/character/s5/jamie-lannister-512x512.jpg"),
    URLImage.createToStorage(placeholder, "cersei","http://i.lv3.hbo.com/assets/images/series/game-of-thrones/character/s5/cersei-lannister-512x512.jpg")
};

MultiButton b = new MultiButton("Pick A Lanister...");
b.addActionListener(e -> {
    Dialog d = new Dialog();
    d.setLayout(BoxLayout.y());
    d.getContentPane().setScrollableY(true);
    for(int iter = 0 ; iter < characters.length ; iter++) {
        MultiButton mb = new MultiButton(characters[iter]);
        mb.setTextLine2(actors[iter]);
        mb.setIcon(pictures[iter]);
        d.add(mb);
        mb.addActionListener(ee -> {
            b.setTextLine1(mb.getTextLine1());
            b.setTextLine2(mb.getTextLine2());
            b.setIcon(mb.getIcon());
            d.dispose();
            b.revalidate();
        });
    }
    d.showPopupDialog(b);
});
hi.add(b);
hi.show();
Form hi=新表单(“按钮”,BoxLayout.y());
字符串[]字符={“提利昂·兰尼斯特”、“詹姆·兰尼斯特”、“瑟曦·兰尼斯特”};
字符串[]演员={“彼得·丁克拉奇”、“尼古拉·科斯特·瓦尔多”、“莉娜·海迪”};
int size=Display.getInstance().convertToPixels(7);
EncodedImage占位符=EncodedImage.createFromImage(Image.createImage(大小,大小,0xFFCCCC),true);
图像[]图片={
createToStorage(占位符,“tyrion”http://i.lv3.hbo.com/assets/images/series/game-of-thrones/character/s5/tyrion-lannister-512x512.jpg"),
createToStorage(占位符,“jaime”http://i.lv3.hbo.com/assets/images/series/game-of-thrones/character/s5/jamie-lannister-512x512.jpg"),
URLImage.createToStorage(占位符“cersei”,”http://i.lv3.hbo.com/assets/images/series/game-of-thrones/character/s5/cersei-lannister-512x512.jpg")
};
MultiButton b=新的MultiButton(“选择一个Lanister…”);
b、 addActionListener(e->{
Dialog d=新建Dialog();
d、 setLayout(BoxLayout.y());
d、 getContentPane().setScrollableY(true);
for(int-iter=0;iter{
b、 setTextLine1(mb.getTextLine1());
b、 setTextLine2(mb.getTextLine2());
b、 setIcon(mb.getIcon());
d、 处置();
b、 重新验证();
});
}
d、 显示弹出对话框(b);
});
加上(b);
嗨,show();


如果坚持使用
组合框
,则可以使用模型为其提供所需的任何对象数据。然后创建单元渲染以显示数据。本节将对此进行深入讨论。请注意,由于
组合框
源自
列表
许多
列表
提示和文档适用于
组合框

谢谢您的快速响应。我确实意识到组合框不是一个好办法,我喜欢多按钮的想法。我唯一不确定的是如何检索所选项目的id。我确信应该有一种方法来获取所选项目的值。我试试看。谢谢。您可以使用get/putClientProperty()在组件上存储元数据。请参见我的回答:谢谢。我试试看。我真的很喜欢这个。