Welcome to the official BlackBerry Support Community Forums.

This is your resource to discuss support topics with your peers, and learn from each other.

inside custom component

Java Development

Determine the number of visible items on the BlackBerry device screen

by Retired ‎02-16-2010 12:22 PM - edited ‎09-16-2010 02:48 PM (1,331 Views)



This article applies to BlackBerry® devices based on Java® technology.




When working with a ListField implementation on a BlackBerry device, you can determine the number of items that are visible on the screen. The method involves finding the vertical area of the ListField that is currently displayed, then dividing that value by the ListField row height.


For a trivial screen with a single ListField, divide the manager's visible height by the row height. If a greater number of fields are on the screen before and after the ListField, the scroll offset should be taken into account.


The following sample code shows how to calculate the actual visible height of the list on the screen and how to use that value to calculate the number of items.



int listRowHeight = list.getRowHeight();
int listTop = list.getTop();
int listBottom = list.getExtent().Y2();
int visibleHeight = list.getManager().getVisibleHeight();
int scrollOffset = list.getManager().getVerticalScroll();

int displayedTop = scrollOffset;
int displayedBottom = scrollOffset + visibleHeight;

if (scrollOffset < listTop) {
    // top of screen before the start of the list
    displayedTop = listTop;
    // remove items on screen that are not in the list
if ((scrollOffset + visibleHeight) > listBottom) {
    // list stops before the end of the screen
    displayedBottom = listBottom;

int displayedHeight = displayedBottom - displayedTop;
int numVisibleItems = 0;

if (listRowHeight > 0) {
    // don't divide by zero
    numVisibleItems = displayedHeight / listRowHeight;
    if ((displayedHeight % listRowHeight) * 4 >= listRowHeight) {
        // Call the row visible if 25% or more is visible

int numHiddenItems = list.getSize() - numVisibleItems;


Users Online
Currently online: 17 members 2,697 guests
Please welcome our newest community members: