Search code examples
lwuit

How to use labels of new Renderer(createed with GUI) in code (LWUIT v1.5)


I've created a Renderer in Resource Editor with three labels(Icon,Destination,lblDate).

And used it in the list with Listmodel event in StateMachine.java

cmp.setModel(new DefaultListModel(payments));
         cmp.setRenderer(new  DefaultListCellRenderer(false) {
        public Component getCellRendererComponent(Component list, Object model, Object value, int index, boolean isSelected) {
               if(value instanceof Payment) { 
                   Payment r = (Payment)value;
                 super.getCellRendererComponent(list, model, r.getPhoneNumber(), index, isSelected);                     
                 setText( r.toString());
                return this;
               }
               return super.getCellRendererComponent(list, model, value, index, isSelected);
        }     
    });

In this code I've could only change the Destination label of renderer

setText( r.toString());

but how to use other labels for example lblDate? How to set them values?


Solution

  • You aren't using the GUI builder for the renderer, you can see a detailed video on how to use that in the Codename One Blog. You are using a DefaultListCellRenderer which is a label so it can only contain a String and an Image, you need to use a more elaborate base and implement the ListCellRenderer interface or use the standard GUI builder support with the Hashtable data model.