Search code examples
listcodenameonerenderer

Horizontal stretching in ListRenderer


I have a list that should display 7 items that each look like this:

Date      Weekday     Distance      Time

Long text that may span many lines

two column text       Distance      Time

two column text       Distance      Time

two column text       Distance      Time

The last lines repeat in a number depending on the data, i e there may be different amounts of such lines for each list item.

I have tried implementing this with a ListCellRenderer that creates a table according to the requirements above, but I have a few problems with it:

  • The long text that may span many lines is implemented in a SpanLabel. But this text will not display more than one line anyway
  • Each item in the list will get space for the same number of lines below the first two..

So it seems that items in a list must be of the same size.

Later I also want to be able to detect selection on the entire list item, not just individual fields of it.

Is there a better way to do this?

How do I ensure that the SpanLabel actually gets as much space as it needs?

How do I ensure that the unknown number of lines gets the space they need, depending on how many they are?


Solution

  • Don't use a list: https://www.codenameone.com/blog/deeper-in-the-renderer.html

    Lists in Codename One assume every entry is exactly the same height and provide no flexibility here.

    I suggest doing something like the property cross demo: https://www.udemy.com/learn-mobile-programming-by-example-with-codename-one/

    Where we use a Container with components within to provide a list like behavior with the full flexibility that arbitrary components allow.