Frage

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!

War es hilfreich?

Lösung

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.

Lizenziert unter: CC-BY-SA mit Zuschreibung
Nicht verbunden mit StackOverflow
scroll top