2016-02-27 24 views
1

我拿了一个空白容器并添加ImageViewer & Spanlabel。同样是在列表中呈现,但它显示我默认输出(我把它放在测试)。我尝试双向动态和手动仍然输出是相同的。即使我尝试使用多列表,但它不采用渲染器。图像和spanlabel渲染列表中的默认输出[CodenameOne]

这里是我的代码:

ArrayList<Map<String, Object>> a = new ArrayList<Map<String, Object>>(); 
    HashMap<String, Object> m = new HashMap<String, Object>(); 
    Image image=fetchResourceFile().getImage("puzzle_icon.png"); 
    m.put("gSR_image", image); 
    m.put("gSR_label", "Puzzle"); 
    a.add(m); 
    cmp.setModel(new com.codename1.ui.list.DefaultListModel(a)); 

看到这个输出

see this output

我的渲​​染画面

my renderer screen

输出必须是我的形象和困惑写在其下方。

回答

2

在spanlabel中存在一些问题,所以用textarea替换spanlabel,并取消选中与上面类似的editable。

ArrayList<Map<String, Object>> a = new ArrayList<Map<String, Object>>(); 
HashMap<String, Object> m = new HashMap<String, Object>(); 
Image image=fetchResourceFile().getImage("puzzle_icon.png"); 
m.put("gSR_image", image); 
**m.put("gSR_textarea", "its working");** 
a.add(m); 
cmp.setModel(new com.codename1.ui.list.DefaultListModel(a)); 
+0

另一种选择突出位置:https://www.codenameone.com/manual/components.html#_generic_list_cell_renderer是到'gSR_image'重命名为'gSR_imageFixed',这将防止渲染试图从它取数据。 –

+0

忘了补充说,SpanLabel/Button在渲染器中不能很好地工作。您应该使用TextArea并相应地设置它。还要注意,以上组件将** NOT **行像在普通容器中那样动态地中断。 –

+0

@ShaiAlmog你的解决方案使用文本,但对于图像相同是行不通的。我试着在末尾加上'Fixed'字样,但是这个标签不是'ImageViewer',而是强制'Label'来选择在渲染器中设置的图像。最后,解决哪个工作是用'Label'和'name'代替'ImageViewer'必须在末尾没有'Fixed'字样。 'Image image = fetchResourceFile()。getImage(“puzzle_icon.png”); m.put(“gSR_image”,图片);'现在这个工作很完美。 –