1. Shreyas's Avatar
    Hi all,

    I m creating a ListField with Checkboxes from How To - Create a ListField with check boxes

    But I m not getting how to wrap Text in a row in that ListField.

    I referred the thread Text Wrapping for text in List Field items

    Here its written as

    Code:
    If all you are displaying is text, then I would go with the approach suggested by rab.
    I m displaying Text only in ListField which I want to wrap if it doesnt fit within device screen.

    But i m not getting "approach suggested by rab" in which How to calculate?

    Code:
    String [] linesToDraw = calculate the number of lines depending on the row width
    I m stucked at this so any details on this issue ?
    11-28-09 05:11 AM
  2. andiamo's Avatar
    Hi all,

    I m creating a ListField with Checkboxes from How To - Create a ListField with check boxes

    But I m not getting how to wrap Text in a row in that ListField.

    I referred the thread Text Wrapping for text in List Field items

    Here its written as

    Code:
    If all you are displaying is text, then I would go with the approach suggested by rab.
    I m displaying Text only in ListField which I want to wrap if it doesnt fit within device screen.

    But i m not getting "approach suggested by rab" in which How to calculate?

    Code:
    String [] linesToDraw = calculate the number of lines depending on the row width
    I m stucked at this so any details on this issue ?
    Your drawing routine needs to calculate where to split the long line of text onto multiple lines.

    For example say the width of your screen is the line below.

    ________________________________
    This row is a long string of characters that goes off the screen.

    drawListRow needs to figure out where to split the lines. So it would get the width of the entire string, see that it's too long, and start removing words until it gets a string that is less wide than the screen. It'd eventually be left with "This row is a long string of" "characters that goes off the screen."


    To me, it seems like too much of a pain to do this. Instead, what I did was create a marquee scroller. If the text is too long, it starts scrolling to the left. It's a simple matter of using a timer and calling graphics.drawText while reducing the X value each frame.
    Last edited by Andiamo; 11-28-09 at 09:50 PM.
    11-28-09 08:53 PM
  3. Shreyas's Avatar
    So will u please give me code snippet of ur marquee scroller as i m not clear with it
    12-01-09 02:02 AM
  4. andiamo's Avatar
    Sorry, I won't paste code because it is part of a custom ObjectListField class that has a LOT of other code in it.

    However, it is not difficult to achieve. First, create a new class that extends ObjectListView. Create an integer instance variable called scrollXPosition... this will keep track of the position of the scroller. Create a new Timer and have the Timer decrement the value of scrollXPosition each tick, then call invalidate(). In your drawListRow method, replace the graphics.drawText() at the end of the method with...

    Code:
    graphics.drawText(rowString.toString(), scrollXPosition, y, 0, w);
    Once this is done the row will start scrolling to the left to reveal text that goes off the screen.

    However there are some other things you'll need to solve, including:
    1) The logic that decides when to start and stop the Timer
    2) When the user selects a different item, reset scrollXPosition to 0
    3) When the text goes completely off the screen, reset scrollXPosition to 0

    Good luck!
    12-02-09 04:49 PM
LINK TO POST COPIED TO CLIPBOARD