Welcome!

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

Reply
Contributor
xavic
Posts: 16
Registered: ‎11-06-2012
My Device: BlackBerry 9800
My Carrier: N/A

scroll in SimpleList

[ Edited ]

I'm developing an app for BlackBerry 6, and testing it with a Torch 9800.

 

I am using a SimpleList to display a list with more items than fit in the screen.
The problem is that the scroll doesn't work as expected when using the trackpad:
When the list is first displayed, the focus is in the first item. When I move the finger vertically (from top to bottom) on the trackpad, I was expecting that the focus changes to the second item (as it happens when the complete list fits in the screen), but instead nothing seems to happen. I have to repeat this movement 5 or 6 times more for something to happen, but what happens then is that the item 22 is focused. Not what I was expecting.

 

I have copied the code below. I would greatly appreciate if someone can point how to get the expected behaviour.
Thanks!


import net.rim.device.api.ui.Manager;
import net.rim.device.api.ui.component.table.SimpleList;
import net.rim.device.api.ui.container.MainScreen;

 

public class TestListScreen extends MainScreen {

    public TestListScreen() {

        super(Manager.NO_VERTICAL_SCROLL);

        Manager mainManager = getMainManager();
        final SimpleList listField = new SimpleList(mainManager);
        for (int i = 0; i < 50; i++) {
            listField.add(Integer.toString(i));
        }

    }

 

}

Please use plain text.
Developer
kamal_nigam
Posts: 434
Registered: ‎07-23-2012
My Device: Blackberry 10
My Carrier: Orange

Re: scroll in SimpleList

try with the following link

http://docs.blackberry.com/en/developers/deliverables/18125/Simple_list_1228593_11.jsp

 

or following code

 

 

class CustomListField extends ListField implements ListFieldCallback 
{
public static int x;
public Vector rows;
private Bitmap p1;
int z = this.getRowHeight();
public LabelField label,label2,label3,label4,label5;
public CustomListFieldCode(int rowcount,int service_No,String text1,String time)
{
    super(0, ListField.MULTI_SELECT);
    setRowHeight(3*z);
    setEmptyString("Hooray, no tasks here!", DrawStyle.HCENTER);
    setCallback(this);        
    rows = new Vector();

    for (x = 0; x < rowcount; x++) 
    {
        TableRowManager row = new TableRowManager();
        if(x%2==0)
        row.setBackground(BackgroundFactory.createSolidBackground(Color.AQUA));
        label = new LabelField("Service"+x);
        row.add(label);
        rows.addElement(row);
    }
    setSize(rows.size());

}

  // ListFieldCallback Implementation
  public void drawListRow(ListField listField, Graphics g, int index, int y,int width) 
  {
    CustomListFieldCode list = (CustomListFieldCode) listField;
    TableRowManager rowManager = (TableRowManager) list.rows.elementAt(index);        
    rowManager.drawRow(g, 0, y, width, list.getRowHeight());
}

private class TableRowManager extends Manager 
{
    public TableRowManager() 
    {
    super(0);
    }

// Causes the fields within this row manager to be layed out then
// painted.
    public void drawRow(Graphics g, int x, int y, int width, int height) 
    {
        // Arrange the cell fields within this row manager.
        layout(width, height);

        // Place this row manager within its enclosing list.
        setPosition(x, y);

        // Apply a translating/clipping transformation to the graphics
        // context so that this row paints in the right area.
        g.pushRegion(getExtent());

        // Paint this manager's controlled fields.
        subpaint(g);

        g.setColor(0x00CACACA);
        //g.drawLine(0, 0, getPreferredWidth(), 0);

        // Restore the graphics context.
        g.popContext();
    }

    // Arrages this manager's controlled fields from left to right within
    // the enclosing table's columns.
    protected void sublayout(int width, int height) 
    {
        // write your code for arranging the elements of the row
    }

// The preferred width of a row is defined by the list renderer.
    public int getPreferredWidth() 
    {
        return Graphics.getScreenWidth();
    }

    // The preferred height of a row is the "row height" as defined in the
    // enclosing list.
    public int getPreferredHeight() 
    {
        return getRowHeight();
    }
}

public Object get(ListField listField, int index) 
{
    // TODO Auto-generated method stub
    return null;
}

public int getPreferredWidth(ListField listField) 
{
    // TODO Auto-generated method stub
    return 0;
}

public int indexOfList(ListField listField, String prefix, int start) 
{
    // TODO Auto-generated method stub
    return 0;
}


}

 

Thanks
-------------------------------------------------------------------------------------
Press the Accept as solution Button when u got the Solution
Press Kudo to say thank to developer.
-------------------------------------------------------------------------------------.
Please use plain text.
Contributor
xavic
Posts: 16
Registered: ‎11-06-2012
My Device: BlackBerry 9800
My Carrier: N/A

Re: scroll in SimpleList

Actually the code I posted is based on the SimpleListDemo of the page you linked to.

 

What's more, I've just tried that SimpleListDemo code exactly as it's listed and, by just changing the number of items in the list to 21 or more (the minimum items required to fill an entire screen), it stops working (with a java.lang.NullPointerException).

Is this the normal behavior?

Is it necessary to create a custom ListField to get a list that handles scrolling?

 

(Anyway, this CustomListField you posted didn't work for me either: it shows an empty list, and although the focus can be moved, once it reaches the last row of the screen, if you continue moving down, it disappears, which I guess it means that the list is not scrolling.)

Please use plain text.
Developer
peter_strange
Posts: 19,601
Registered: ‎07-14-2008
My Device: Not Specified

Re: scroll in SimpleList

[ Edited ]

Apologies, I had a wee battle with this and lost.  Basically I don't understand this Field or the requirement to be added to a non scrolling manager.  it seems flawed but someone in RIM approved it, so I guess it is just me.  I never use this, I use LstField instead.  So I can't justify the time to look at this and I need to work on some other things.  Sorry. 

 

Please use plain text.
Contributor
xavic
Posts: 16
Registered: ‎11-06-2012
My Device: BlackBerry 9800
My Carrier: N/A

Re: scroll in SimpleList

ok, so I guess I better forget about SimpleList and use a custom ListField instead.

 

Searching for more info about using ListField I've found this sample code by you...

http://supportforums.blackberry.com/t5/Java-Development/Simple-ListField-example/m-p/431294#M84639

 

Does this handle scrolling?

 

Thanks in advance.

Please use plain text.
Developer
peter_strange
Posts: 19,601
Registered: ‎07-14-2008
My Device: Not Specified

Re: scroll in SimpleList

Did I write that!  I had completely forgotten....

 

Yes it handles scrolling.

 

If you want another example, have a look at this:

http://supportforums.blackberry.com/t5/Java-Development/ListField-that-scrolls-Horizontally/td-p/202...

 

You can try that code and prove it handles scrolling!

Please use plain text.