1. swarsa's Avatar
    I have read many other posts on ListField scrolling and they have helped me to get this far, but now I am stuck. I have my list field in a VerticalManager with scrolling working. I have it set up so that there are 5 visible rows in the ListField. However, when I scroll past the last visible row (currently there are a total of 9 rows in the list), the rows no longer paint the text of the row. I have developed a Custom ListField implementation that has a foreground and background color. The idea is that as each row is focused, the foreground and background color switch - the selected row has navy background with white text and unselected rows have white background with navy text. Works great for the visible rows, but when I scroll past row 5 to reveal the invisible rows, they are just painting with the navy background and no white text. Here is my custom list field class (which was based off of something I found either on a forum or in the knowledge base):



    import net.rim.device.api.ui.Graphics;
    import net.rim.device.api.ui.XYRect;
    import net.rim.device.api.ui.component.ListField;

    public class ColoredListField extends ListField
    {
    private boolean hasFocus = false;
    private final int fixedWidth;
    private int fgcolor;
    private int bgcolor;
    private final int fixedHeight;

    public ColoredListField(int width, int height, int fgcolor, int bgcolor)
    {
    this.fixedWidth = width;
    this.fixedHeight = height;
    this.fgcolor = fgcolor;
    this.bgcolor = bgcolor;
    }

    public int getPreferredWidth()
    {
    return fixedWidth;
    }

    public void layout(int width, int height)
    {
    setExtent(fixedWidth, fixedHeight);
    }

    public int moveFocus(int amount, int status, int time)
    {
    invalidate(getSelectedIndex());
    return super.moveFocus(amount, status, time);
    }

    public void onFocus(int direction)
    {
    hasFocus = true;
    super.onFocus(direction);
    invalidate();
    }

    public void onUnfocus()
    {
    hasFocus = false;
    super.onUnfocus();
    invalidate();
    }

    public void paint(Graphics graphics)
    {
    // Get the current clipping region as it will be the only part that
    // requires repainting
    XYRect redrawRect = graphics.getClippingRect();
    if (redrawRect.y < 0)
    throw new IllegalStateException(
    "The 'y' variable of the clipping " +
    "rectangle is < 0: " + redrawRect.y);

    // If the ListField has focus determine the selected row.
    int rowHeight = getRowHeight();
    int currEntry = redrawRect.y / rowHeight;
    int lastVisibleEntry = (redrawRect.y + redrawRect.height - 1) / rowHeight;
    lastVisibleEntry = Math.min(lastVisibleEntry, getSize() - 1);
    int y = currEntry * rowHeight;

    int curSelected = hasFocus ? getSelectedIndex() : -1;
    // Draw each row
    for (; currEntry <= lastVisibleEntry; ++currEntry)
    {
    graphics.setColor(currEntry == curSelected ? bgcolor : fgcolor);
    graphics.fillRect(0, y, redrawRect.width, rowHeight);
    graphics.setColor(currEntry == curSelected ? fgcolor : bgcolor);
    graphics.drawText(getCallback().get(this, currEntry).toString(), 0,
    y);
    // Assign new values to the y axis moving one row down.
    y += rowHeight;
    }
    }
    }


    Here is how I instantiate the class:



    private int screenW = Graphics.getScreenWidth();
    private int screenH = Graphics.getScreenHeight();
    private int listWidth = (int) (screenW * 0.95);
    private int listHeight = (int) (screenH * 0.4);
    private ColoredListField myListField = new ColoredListField(
    listWidth, listHeight, selectedFGColor, selectedBGColor);




    Also, here is my callback:



    private static class DiaryEntryListCallback implements ListFieldCallback
    {
    private DiaryEntry[] diaryEntryList;

    public DiaryEntryListCallback() throws Exception
    {
    diaryEntryList = new DiaryEntry[0];
    init();
    }

    public void init() throws Exception
    {
    DiaryEntry[] tmpDiaryEntryList =
    DiaryDAO.instance().getDiaryEntriesAsArray(true);
    if (tmpDiaryEntryList != null && tmpDiaryEntryList.length > 0)
    diaryEntryList = tmpDiaryEntryList;
    else
    {
    diaryEntryList = new DiaryEntry[1];
    diaryEntryList[0] = new DiaryEntry("No data",
    Calendar.getInstance());
    }
    }

    public void init(DiaryEntry[] diaryEntries) throws Exception
    {
    diaryEntryList = diaryEntries;
    }

    public int getNumberOfRows()
    {
    return diaryEntryList.length;
    }

    public void drawListRow(ListField l, Graphics g, int index, int y, int w)
    {
    // drawing text is handled by the custom list field implementation
    }

    public Object get(ListField listField, int index)
    {
    return diaryEntryList[index];
    }

    public int getPreferredWidth(ListField listField)
    {
    return listField.getPreferredWidth();
    }

    public int indexOfList(ListField listField, String prefix, int start)
    {
    int size = diaryEntryList.length;
    for (int i = 0; i < size; i++)
    {
    DiaryEntry currEntry = (DiaryEntry) diaryEntryList[i];
    if (currEntry.getEntryText().toLowerCase().startsWith (
    prefix.toLowerCase()))
    return i;
    }
    return listField.getSelectedIndex();
    }
    }



    And here is where I build the main screen, adding the list field and other fields to it:



    private void createMainScreen()
    {
    mainMgr = new ColoredVerticalManager(selectedBGColor,
    Manager.USE_ALL_HEIGHT);
    listMgr = new ColoredVerticalManager(
    selectedBGColor,
    Manager.VERTICAL_SCROLL | Manager.VERTICAL_SCROLLBAR);
    mainMgr.add(diaryEntriesLabel = new FixedWidthLabelField(
    "Diary Entries:", listWidth, -1, selectedFGColor, selectedBGColor));
    try
    {
    listCallback = new DiaryEntryListCallback();
    diaryEntriesListField.setSize(listCallback.getNumb erOfRows());
    diaryEntriesListField.setCallback(listCallback);
    diaryEntriesListField.setFocusListener(new DiaryFocusListener());
    listMgr.add(diaryEntriesListField);
    mainMgr.add(listMgr);
    }
    catch (Exception e)
    {
    Dialog.alert("Error loading diary entry list: " + e.getMessage());
    }
    mainMgr.add(selectedEntryLabel = new FixedWidthLabelField(
    "Selected Entry:", -1, -1, selectedFGColor, selectedBGColor));
    mainMgr.add(diaryEntry);
    add(mainMgr);
    }




    Any clues as to why when scrolling past the visible rows, it stops painting?



    Thanks,

    Steve
    12-23-08 06:38 AM
  2. delta_foxtrot2's Avatar
    You need to make something focusable, it's a bit late here so I didn't skim your code, but to have things scroll they must be able to accept focus, alternatively you can use nullfields if you don't want real things to be selectable.
    12-23-08 06:56 AM
  3. swarsa's Avatar
    Hey, thanks for the quick reply. The whole field can certainly accept focus and I do override move focus:

    public int moveFocus(int amount, int status, int time)
    {
    invalidate(getSelectedIndex());
    return super.moveFocus(amount, status, time);
    }

    Which causes my custom row paint method to be invoked. The rows do paint correctly on the 'visible' rows, it is just when I move to the 'invisble' rows. the visible rows are scrolling out of view and painting correctly, but the new rows that should be shown at the bottom of the list as the scroll happens are not painting correctly...
    12-23-08 07:06 AM
  4. delta_foxtrot2's Avatar
    That's my point, each item that you want to "show" has to have focus, at least that's been my experience in the limited time I've been coding for the BB platform.
    12-23-08 07:24 AM
  5. delta_foxtrot2's Avatar
    Alternatively stick a nullfield with focus between each item you want to show.
    12-23-08 07:24 AM
  6. patrick.waugh's Avatar
    NOTE: When posting code, post it with the CODE tags (use "#" in the toolbar).

    Reposted code (with some improved formating)

    Code:
    private void createMainScreen() {
    	mainMgr = new ColoredVerticalManager( selectedBGColor, Manager.USE_ALL_HEIGHT );
    	listMgr = new ColoredVerticalManager( selectedBGColor, Manager.VERTICAL_SCROLL | Manager.VERTICAL_SCROLLBAR);
    	mainMgr.add(diaryEntriesLabel = new FixedWidthLabelField( "Diary Entries:", listWidth, -1, selectedFGColor, selectedBGColor));
    
    	try {
    		listCallback = new DiaryEntryListCallback();
    		diaryEntriesListField.setSize(listCallback.getNumb erOfRows());
    		diaryEntriesListField.setCallback(listCallback);
    		diaryEntriesListField.setFocusListener(new DiaryFocusListener());
    		listMgr.add(diaryEntriesListField);
    		mainMgr.add(listMgr);
    	} catch (Exception e) {
    		Dialog.alert("Error loading diary entry list: " + e.getMessage());
    	}
    	
    	mainMgr.add(selectedEntryLabel = new FixedWidthLabelField( "Selected Entry:", -1, -1, selectedFGColor, selectedBGColor));
    	mainMgr.add(diaryEntry);
    	add(mainMgr);
    }
    
    // Sample instantiation
    private int screenW = Graphics.getScreenWidth();
    private int screenH = Graphics.getScreenHeight();
    private int listWidth = (int) (screenW * 0.95);
    private int listHeight = (int) (screenH * 0.4);
    private ColoredListField myListField = new ColoredListField( listWidth, listHeight, selectedFGColor, selectedBGColor );
    
    // Callback
    private static class DiaryEntryListCallback implements ListFieldCallback {
    	private DiaryEntry[] diaryEntryList;
    	
    	public DiaryEntryListCallback() throws Exception {
    		diaryEntryList = new DiaryEntry[0];
    		init();
    	}
    
    	public void init() throws Exception {
    		DiaryEntry[] tmpDiaryEntryList = DiaryDAO.instance().getDiaryEntriesAsArray(true);
    		
    		if (tmpDiaryEntryList != null && tmpDiaryEntryList.length > 0) {
    			diaryEntryList = tmpDiaryEntryList;
    		} else {
    			diaryEntryList = new DiaryEntry[1];
    			diaryEntryList[0] = new DiaryEntry("No data",
    			Calendar.getInstance());
    		}
    	}
    
    	public void init(DiaryEntry[] diaryEntries) throws Exception {
    		diaryEntryList = diaryEntries;
    	}
    
    	public int getNumberOfRows() { return diaryEntryList.length; }
    
    	public void drawListRow(ListField l, Graphics g, int index, int y, int w) {
    		// drawing text is handled by the custom list field implementation
    	}
    
    	public Object get(ListField listField, int index) {
    		return diaryEntryList[index];
    	}
    
    	public int getPreferredWidth(ListField listField) {
    		return listField.getPreferredWidth();
    	}
    
    	public int indexOfList(ListField listField, String prefix, int start) {
    		int size = diaryEntryList.length;
    
    		for (int i = 0; i < size; i++) {
    			DiaryEntry currEntry = (DiaryEntry) diaryEntryList[i];
    		
    			if (currEntry.getEntryText().toLowerCase().startsWith (prefix.toLowerCase())) {
    				return i;
    			}
    		}
    	return listField.getSelectedIndex();
    	}
    }
    
    // Extended ListField Class
    public class ColoredListField extends ListField {
    
    	private boolean hasFocus = false;
    	private final int fixedWidth;
    	private int fgcolor;
    	private int bgcolor;
    	private final int fixedHeight;
    	
    	public ColoredListField(int width, int height, int fgcolor, int bgcolor) {
    		fixedWidth = width;
            fixedHeight = height;
            fgcolor = fgcolor;
            bgcolor = bgcolor;
        }
    
        public int getPreferredWidth() { return fixedWidth; }
    
    	public void layout(int width, int height) {
    		setExtent(fixedWidth, fixedHeight);
    	}
    
    	public int moveFocus(int amount, int status, int time) {
    		invalidate(getSelectedIndex());
    		return super.moveFocus(amount, status, time);
    	}
    
        public void onFocus(int direction) {
            hasFocus = true;
            super.onFocus(direction);
            invalidate();
        }
    
        public void onUnfocus() {
            hasFocus = false;
            super.onUnfocus();
            invalidate();
        }
    
        public void paint(Graphics graphics) {
            // Get the current clipping region as it will be the only part that
            // requires repainting
            XYRect redrawRect = graphics.getClippingRect();
            if (redrawRect.y < 0)
                throw new IllegalStateException(
                    "The 'y' variable of the clipping " +
                    "rectangle is < 0: " + redrawRect.y);
    
            // If the ListField has focus determine the selected row.
            int rowHeight = getRowHeight();
            int currEntry = redrawRect.y / rowHeight;
            int lastVisibleEntry = (redrawRect.y + redrawRect.height - 1) / rowHeight;
            lastVisibleEntry = Math.min(lastVisibleEntry, getSize() - 1);
            int y = currEntry * rowHeight;
    
            int curSelected = hasFocus ? getSelectedIndex() : -1;
    
            // Draw each row
            for (; currEntry <= lastVisibleEntry; ++currEntry) {
                graphics.setColor(currEntry == curSelected ? bgcolor : fgcolor);
                graphics.fillRect(0, y, redrawRect.width, rowHeight);
                graphics.setColor(currEntry == curSelected ? fgcolor : bgcolor);
                graphics.drawText(getCallback().get(this, currEntry).toString(), 0, y);
    
                // Assign new values to the y axis moving one row down.
                y += rowHeight;
            }
        }
    
    }
    12-23-08 11:14 AM
  7. patrick.waugh's Avatar
    Have you thought about getting yourself a good book on the basics?

    I'd recommend "Head First Java", which also covers some basic Swing, which is what the BB API is modeled after. In other words, if you know Swing, the BB API is so similar that you will mostly understand how to use it.

    Trying to code something by copying an example and modifying it is not going get you far, especially when you don't understand what you are doing. For example, you are casting and int to int above, and also clearly don't understand the implications of overriding a method in a derived class.

    After that book, which will give you some basics of Java and OOP, you'll want to learn a little about design patterns.

    Good luck
    12-23-08 11:24 AM
  8. swarsa's Avatar
    Hello Patrick,

    I am an experienced java developer (SE, ME, EE) and have been doing it since 1998. I fully understand the implications of casting to an int and of overriding superclass methods as well as design patterns. If the "casting and int to int" comment was referring to this line:

    private int listWidth = (int) (screenW * 0.95);

    It won't even compile if you take out the cast to an int. What are you talking about? Please be more specific with your criticism. Also, you may want to actually try to contribute something to the conversation (like a potential solution), rather than a random pot shot.

    Steve
    12-24-08 05:46 AM
  9. delta_foxtrot2's Avatar
    private int listWidth = (int) (screenW * 0.95);
    I use that to do simple rounding too, works for me(tm).

    Also, you may want to actually try to contribute something to the conversation (like a potential solution), rather than a random pot shot.
    did you have any luck with my suggestions about making line items focusable? been flat out with work all day and haven't had time for much else.

    I wrote a simple app a few weeks back that scrolls like this:

    vfm.add(new LabelField(string, Field.FOCUSABLE));
    12-24-08 07:14 AM
  10. swarsa's Avatar
    Hi delta_foxtrot2,

    I appreciate the response. The comments you quoted from me were actually replies to Patrick's post, not yours.

    No, I have not had the chance to implement your suggestions yet. The point is that the items in the list are accepting focus as I scroll through the list. Each item is repainting correctly as it receives focus (switching the foreground and background color). This is working correctly. The ONLY problem is when the 6th row of the list (which is initially not visible) does not display correctly when it is revealed. Maybe I am misunderstanding your suggestion here... In case it would help, I have provided some screen shots below. This one is with the first record selected:



    then here is one with the 6th record in the list selected:



    Let me know if that helps. I appreciate your thoughtful response on this delta_foxtrot2.

    thanks,
    Steve
    12-24-08 07:50 AM
  11. patrick.waugh's Avatar
    Steve,

    First, apologies. I didn't look at your code very long, and was a bit tired. I didn't notice (duh) that the cast to int was necessary due to a promotion to double. When someone doesn't even bother to make it readable with the CODE tags, I am not to motivated to look to hard, but I tried to help by showing you how to do that at least.

    I believe this code is your problem:

    Code:
    public void drawListRow(ListField l, Graphics g, int index, int y, int w) {
    	// drawing text is handled by the custom list field implementation
    }
    When I looked at this quickly last night, this stood out like a sore thumb, but for the wrong reason. I originally just thought maybe you had override a method, and not called the super(), thus not having the row draw. However, that isn't it at all, as you already know.

    If I read your code right, you have decided to attempt to have the ListField handle the painting of the row. However, I don't think (in this case at least) you can get away with this. Basically, I think if you move the code which draws the rows to where it belongs, back in the callback, it should work. The problem you are experiencing is because the framework is not calling the paint() in your LIstField like you think, but rather calling the callback method you left blank.

    Alternatively, you "might" be able to get it to work the way it is (although at some cost in performance) if you invalidate() the ListField entirely so it is completely redraw onFocus() (better than using a listener for the change in this case).

    I seem to remember someone talking about a bug in one version when trying to flip the foreground/background colors in a ListField, so you might check that out too if this doesn't work.

    Hope that helps,

    Patrick
    12-24-08 11:46 AM
  12. swarsa's Avatar
    Hi Patrick,

    Apologies accepted. Actually the paint method is working for the rows in the list which are initially visible, but when I scroll to the 6th row, which is not initially visible, then that row is not rendered correctly. Earlier, someone had suggested moving the code for painting a row into the drawListRow method, so I commented out the paint method from the ListField sublclass and refactored the contents of that paint method to work inside the drawListRow:

    Code:
            
            public void drawListRow(ListField l, Graphics g, int index, int y, int w)
            {
                ColoredListField clf = (ColoredListField) l;
                g.setColor(index == l.getSelectedIndex() ? clf.getBGColor() : clf.getFGColor());
                g.fillRect(0, y, w, l.getRowHeight());
                g.setColor(index == l.getSelectedIndex() ? clf.getFGColor() : clf.getBGColor());
                g.drawText(get(l, index).toString(), 0, y);
            }
    Unfortunately, the result is the same - so it seems that whether I handle the painting of the entire list in the paint method of the ListField subclass, or whether I handle the painting of individual rows in the ListFieldCallback.drawListRow the result is the same. It renders each row correctly as each row gains and loses focus, but when focus gets to the sixth row (which is where the first scroll to an invisible row occurs), no text is shown for that row even though I know from the debugger that the data is there. I have posted screen shots in a previous post. Also, I have tried invalidating the whole thing and that didn't work either.

    Also, I've heard about that bug. I think it related to horizontal scrolling - I could be wrong though. I looked at it and decided that it didn't apply to my situation.

    Thanks for taking the time to look at it and respond. This is a tough nut to crack.

    FYI,
    Steve
    12-24-08 12:41 PM
  13. patrick.waugh's Avatar
    What jde are you targeting? What OS?

    I think this is the bug I was thinking of... but again I haven't checked. Each "line" is actually a "field" in a VFM (the ListBox itself) and I had heard people complain that they were not repainting properly when they tried to customize the background.

    Only other idea I have is to maybe take the color change out of the equation and see if it works at all.

    Patrick
    12-24-08 12:53 PM
  14. delta_foxtrot2's Avatar
    I appreciate the response. The comments you quoted from me were actually replies to Patrick's post, not yours.
    I know, I was trying to calm things down, I don't know why Patrick has to belittle everyone the way he does.

    xmas day here and I'm just doing a quick reply, will do something more thoughtful in the coming days if you are unable to solve it sooner.
    12-24-08 07:42 PM
  15. patrick.waugh's Avatar
    I know, I was trying to calm things down, I don't know why Patrick has to belittle everyone the way he does.

    xmas day here and I'm just doing a quick reply, will do something more thoughtful in the coming days if you are unable to solve it sooner.
    Delta, he is an adult and doesn't need you to defend him. Please observe policy and respond to the OP, and not try to start stuff with trolling comments such as this post. If you have an issue with a post, report it to a moderator, rather than take matters into your own hands as you are supposed to do.

    If you think you can solve his issue, great, do it and leave it at that. Have you even written a single working Blackberry program yet? Just curious. Maybe you should concentrate on that instead of trolling in the forums.

    Steve, my advice would be to post your code on the BB dev forum where there are many more experienced eyes looking at it that are also familiar with the API and various known bugs (if you haven't already). Once they know you know what you are doing, people jump right in even before RIM's guy gets around to it if they know the answer. I haven't done a lot with ListFields myself (only used it once so far), so nothing is jumping out at me.

    I know there are a lot of cases where things just don't work like I would have thought based on Swing. Usually, of course, this is just due to a lack of generics.

    I currently have a similar issue which is very frustrating and no one has been able to solve yet either. But, since it is Christmas I've put it on hold for my girlfriend. She can be very distracting. =)

    Anyway, Merry Christmas and good luck,

    Patrick
    12-24-08 09:40 PM
  16. delta_foxtrot2's Avatar
    Delta, he is an adult and doesn't need you to defend him. Please observe policy and respond to the OP, and not try to start stuff with trolling comments such as this post. If you have an issue with a post, report it to a moderator, rather than take matters into your own hands as you are supposed to do.
    Actually my statement was factual, you do belittle people, and I was going to rant and rave about how you should grow up and stop belittling people you perceive to be beneath you, instead I'm just going to say this, "If you don't have anything nice to say, or you can't answer the question actually asked, shut the **** up, it's as if you are trying to win the highest number of posts possible while being the least helpful".

    If you think you can solve his issue, great, do it and leave it at that. Have you even written a single working Blackberry program yet? Just curious. Maybe you should concentrate on that instead of trolling in the forums.
    Takes one to know one? It's obvious you have no idea what I've done or doing you just like the sound of your own posts...

    Steve, my advice would be to post your code on the BB dev forum where there are many more experienced eyes looking at it that are also familiar with the API and various known bugs (if you haven't already).
    Yea well it's obvious you aren't going to help him out with all your wisdom, your first post in this thread was absolutely pointless, along with most of your others.

    I currently have a similar issue which is very frustrating and no one has been able to solve yet either.
    What problem would that be exactly?

    Actually I've posted serious questions in the past and you never bother to reply to them either.
    Last edited by delta_foxtrot2; 12-25-08 at 04:03 AM.
    12-25-08 04:00 AM
  17. swarsa's Avatar
    Patrick,

    I think the bug you are referring to may be "How To - Work around ListField painting issue in early versions of BlackBerry Device Software version 4.2.2" (I don't have enough posts yet to post a link).

    However, I really don't think that applies to my situation. The reason is because it says:

    You can work around this issue by not using the HORIZONTAL_SCROLL style in the Manager
    And I am not using the HORIZONTAL_SCROLL style in the Manager that contains this list. Based in information in the article, I am testing against the version that is affected by this bug. I am testing with the Blackberry 8310 Rogers simulator, which is the BB Curve (v4.2.2.163). Compiling against the JDE 4.7.

    Here is the rest of the article:

    This article applies to the following:

    * BlackBerry� 8830 World Edition smartphone
    * BlackBerry� Curve� 8300 smartphone
    * BlackBerry� Device Software version 4.2.2
    Description

    Early versions of BlackBerry Device Software version 4.2.2 have an issue with painting ListField UI objects and scrolling. When the cursor is on odd-numbered lines, starting with the first line, the object is not painted. Scrolling to an even-numbered line causes the entire object to be painted.

    You can work around this issue by not using the HORIZONTAL_SCROLL style in the Manager, as shown below.
    Code:
    private static final class TestScreen extends MainScreen {
             private final ObjectListField listField = new ObjectListField(USE_ALL_WIDTH);
             private final String[] lines = { "Line 1", "Line 2", �Line 3", "Line 4", "Line 5", "Line 6" };
             private TestScreen() {
                      super(DEFAULT_MENU | DEFAULT_CLOSE);
                      final Manager man = new VerticalFieldManager(VERTICAL_SCROLL | VERTICAL_SCROLLBAR);
                      add(man);
                      man.add(listField);
                      listField.set(lines);
            }
    }
    Again, here is the Manager where the my custom ListField subclass is being added (see the variable 'listMgr' in the 'createMainScreen' method below):

    Code:
        private void createMainScreen()
        {
            mainMgr = new ColoredVerticalManager(selectedBGColor,
                Manager.USE_ALL_HEIGHT);
            listMgr = new ColoredVerticalManager(
                selectedBGColor,
                Manager.VERTICAL_SCROLL | Manager.VERTICAL_SCROLLBAR);
            mainMgr.add(diaryEntriesLabel = new FixedWidthLabelField(
                "Diary Entries:", listWidth, -1, selectedFGColor, selectedBGColor));
            try
            {
                listCallback = new DiaryEntryListCallback();
                diaryEntriesListField.setSize(listCallback.getNumberOfRows());
                diaryEntriesListField.setCallback(listCallback);
                diaryEntriesListField.setFocusListener(new DiaryFocusListener());
                listMgr.add(diaryEntriesListField);
                mainMgr.add(listMgr);
            }
            catch (Exception e)
            {
                Dialog.alert("Error loading diary entry list: " + e.getMessage());
            }
            mainMgr.add(selectedEntryLabel = new FixedWidthLabelField(
                "Selected Entry:", -1, -1, selectedFGColor, selectedBGColor));
            mainMgr.add(diaryEntry);
            add(mainMgr);
        }
    In case you are wondering what the ColoredVerticalManager is doing, here it is:
    Code:
    import net.rim.device.api.ui.Graphics;
    import net.rim.device.api.ui.container.VerticalFieldManager;
    
    /**
     * @author Steve Warsa
     */
    public class ColoredVerticalManager extends VerticalFieldManager
    {
        private int bgcolor;
    
        public ColoredVerticalManager(int bgcolor, long style)
        {
            super(style);
            this.bgcolor = bgcolor;
        }
    
        public void paint(Graphics graphics)
        {
            // Sets the BackgroundColor
            graphics.setBackgroundColor(bgcolor);
            // Clears the entire graphic area to the current background
            graphics.clear();
            super.paint(graphics);
        }
    }
    Also, I wanted to let you know that I have submitted this problem to 3 forums:

    - BlackBerryForums at Crackberry.com (this site)
    - BlackBerryForums.com
    - BlackBerry Support Community Forums at supportforums.blackberry.com

    On supportforums.blackberry.com, there is someone (Mark Sohm) who seems to be interested in helping out with this as well.
    12-25-08 06:33 AM
  18. swarsa's Avatar
    I just noticed that going through the debugger, the 'drawListRow' method is initially getting called with index 0, 1, 2, 3, 4 (i.e. it is displaying the 1st 5 visible rows). Then, when I scroll to the 6th row (index 5), and the 1st row (index 0) scrolls out of view, 'drawListRow' is only getting called 4 times - with index 1, 2, 3, 4. However, I would expect that it would be called 5 times with index 1, 2, 3, 4, 5, since row 1 (index 0) has now scrolled out of view and row 6 (index 5) has now scrolled into view. I think this is definitely a clue as to what is going on. Maybe it is scrolling within the Manager, but the ListField itself is not scrolling the elements?
    12-25-08 06:49 AM
  19. patrick.waugh's Avatar
    I just noticed that going through the debugger, the 'drawListRow' method is initially getting called with index 0, 1, 2, 3, 4 (i.e. it is displaying the 1st 5 visible rows). Then, when I scroll to the 6th row (index 5), and the 1st row (index 0) scrolls out of view, 'drawListRow' is only getting called 4 times - with index 1, 2, 3, 4. However, I would expect that it would be called 5 times with index 1, 2, 3, 4, 5, since row 1 (index 0) has now scrolled out of view and row 6 (index 5) has now scrolled into view. I think this is definitely a clue as to what is going on. Maybe it is scrolling within the Manager, but the ListField itself is not scrolling the elements?
    Yeah, I guess you are right on the bug issue.

    Many managers to keep straight. Sounds like the ListFields own delegate manager is scrolling those 4 up (which is why index 0 doesn't get called), but somehow it is not getting passed the 6th element. Was it instantiated?

    Maybe review all the styles and make sure they all can vertically scroll?

    Glad you made progress. If you get a chance, check out my custom text field painting issue posted on the RIM forum. I posted the whole class, and it would be a useful one to add to your library (if you don't have one already) if we can get it to work. I also have a very nice DialogFieldManager based dialog setup.

    Well, better get off here before my girlfriend comes back.
    12-25-08 03:54 PM
  20. swarsa's Avatar
    I just found out that it is only scrolling the vertical manager - it is not actually scrolling the list field. I found this out by giving the vertical manager a different background color and I could see that the even though in the debugger the selected index of the list field was correct, the list field was not scrolling down to show the selected index (e.g. 5). So, now, I took out the vertical manager that contained the list field and just added the list field to the 'mainMgr' and the list field is not scrolling at all, so I'm back to my original issue - the list field with a fixed height simply does not scroll. Has anyone gotten this to work?

    In my opinion, it seems like the framework is not working as I would expect for a fixed height list (taking up 40% of the height of the screen) with vertical scrolling. So, I'm thinking about going back to the approach of just completely implementing the painting myself. I would get the total height of the repaint rect and divide that by the row height to tell me how many rows to paint. I would always have to track the range of visible rows (start index to end index). This could be based on the current selected index and the previous selected index to indicate a scroll direction. I'm sure it will be complicated, but that seems like my only option now...


    Thanks,

    Steve
    Last edited by swarsa; 12-28-08 at 09:08 AM.
    12-28-08 08:18 AM
  21. patrick.waugh's Avatar
    Did you fix the issue pointed out on the RIM forum (eg. you must use the correct JDE version)???

    I would do that first.
    12-28-08 09:29 AM
  22. swarsa's Avatar
    Yes, I did. The result is the same testing on the 8310, compiling against JDE 4.2.1.
    12-29-08 06:29 AM
  23. patrick.waugh's Avatar
    Sounds like you are making some progress. Just remember that a Manager IS A Field (which I'm sure you know, but it's worth repeating).

    I would think that the ListField uses it's own delegate VFM, so, yes you just need to add the ListField itself to the Manager in which you are putting it as a whole.

    I find that if I'm careful I can save myself a lot of headaches by minimizing the depth of managers by not putting managers within managers unless absolutely necessary.

    Hope you crack it.
    12-29-08 08:03 AM
  24. swarsa's Avatar
    Hello all, the issue has been resolved thanks to a guy with a screen name 'Shubhangi' on the RIM forum. Basically, he told me to remove the overridden layout method from my listfield subclass. He also told me to add the following 2 methods to the VerticalManager containing the list:
    Code:
        
        public int getPreferredHeight()
        {
            return fixedHeight;
        }
               
        protected void sublayout(int width, int height)
        {
            super.sublayout(width, fixedHeight);
            setExtent(width, fixedHeight);
        }
    As well as making sure to use the styles Manager.VERTICAL_SCROLL | Manager.VERTICAL_SCROLLBAR, which I was already doing. I have posted the full solution over on the RIM forum.

    Thanks for all your time on this one,
    Steve
    12-30-08 06:51 AM
  25. davidvthokie's Avatar
    Found the link: http: // www . blackberryforums . com/developer-forum/166750-listfield-scrolling.html
    Last edited by davidvthokie; 07-18-09 at 05:21 PM. Reason: found link
    07-18-09 05:11 PM
LINK TO POST COPIED TO CLIPBOARD