1

I've created the following custom list renderer for lwuit. The renderer extends a checkbox but for some reason, the select and unselect (check/uncheck) functions dont work. If i setselected() all the items come selected and cant be unselected. Heres the sample code;

class TaskListRenderer extends CheckBox implements ListCellRenderer {

        public TaskListRenderer() {
            super();
        }

        public Component getListCellRendererComponent(List list, Object o, int i, boolean bln) {

            Tasks task = (Tasks) o;
            try {
                img = Image.createImage("/three.png");
            } catch (IOException ex) {
                ex.printStackTrace();
            }
//            
            setIcon(img);
            setText(task.getPhoneID() + " " + task.getDate());

            Style style = new Style();//(0xff0000, 0x00ff00, null, byte(128));
            style.setBgColor(0xff0000);
            style.setFgColor(0x00ff00);
            setSelectedStyle(style);
            return this;
        }

        public Component getListFocusComponent(List list) {
            return this;
//            throw new UnsupportedOperationException("Not supported yet.");
        }
    }
bharath
  • 14,283
  • 16
  • 57
  • 95
Thuita Wachira
  • 176
  • 2
  • 16

1 Answers1

3

Hi The line of code you are missing is

Tasks task = (Tasks) o;
setSelected(task.isSelect());

See a working version hope this helps.

On a side note I highly recommend you move the code below to out side of the getListCellRendererComponent because it gets called many many times when displaying a list and will slow down the performance of your app.

img = Image.createImage("/three.png");
drubin
  • 1,012
  • 7
  • 10