0

I have a LWUIT J2ME app with a List. I would like for the background of a cell to change when it is clicked.

The first thing I had to do was set the background transparency and color of the whole list when it is selected. Otherwise, the background of the form behind it shows through when the list is clicked. I did that with this code:

    catList.getSelectedStyle().setBgTransparency(255);
    catList.getSelectedStyle().setBgColor(0x23222a);

This seems to work fine. When clicked, the list bg remains the same color.

Now I want the background of the clicked cell to change color when it is pressed. I tried this (cellCon is a Container):

    cellCon.getPressedStyle().setBgTransparency(255);
    cellCon.getPressedStyle().setBgColor(0xFFFFFF);
    cellCon.getSelectedStyle().setBgTransparency(255);
    cellCon.getSelectedStyle().setBgColor(0xFFFFFF);

But it has no effect. How can I get the effect that I want?

Thanks!

James Harpe
  • 4,315
  • 8
  • 47
  • 74

1 Answers1

2

You have to get the listCellRender component to set the style of the pressed cell. I think that you can do that trying list.getRender and after that, set the Style.

If you are building a custom Render, take a look on this LWUIT Blog ListCellRender There is a method called getListFocusComponent, there you can return a component (like a label) whit the custom style that you want for your focus.

Mun0n
  • 4,438
  • 4
  • 28
  • 46
  • But I'm already trying to set the style of the listcellrenderer component in the getListCellRendererComponent() method. Why would this be different? – James Harpe Sep 17 '13 at 18:07
  • So, are you builidng a custom Render? If this is your case take a look on this http://lwuit.blogspot.com.es/2008/07/lwuit-list-renderer-by-chen-fishbein.html There is a method called getListFocusComponent, there you can return a component (like a label) whit the custom style that you want for your focus. – Mun0n Sep 17 '13 at 19:28
  • ah that was it. i needed to access my cellCon in the getListFocusComponent method and set the style there. Thanks! If you could edit your answer with this info i'll accept it. – James Harpe Sep 18 '13 at 13:44