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
Developer
Posts: 15
Registered: ‎07-30-2009
My Device: Not Specified
Accepted Solution

setRowHeight dramaticly slows down performance

Hi I developed an application using a KeywordFilterField.

 

As I couldn't override drawListRow in the KeywordFilterField, I created a ListCallback class that implements ListFieldCallback that is assigned to the KeywordFilterField.

 

Everything goes perfect until I add list.setRowHeight(45); the application slows down dramaticly.

 

I want to do this because I need two lines in my result list. 

 

Here is ListCallback code: 

 

private static class ListCallback implements ListFieldCallback {

   private Vector listElements = new Vector();

    public void drawListRow(
            ListField list, Graphics g, int index, int y, int w) {
            list.setRowHeight(45);
            DRAW CODE HERE........
        }

        public Object get(ListField list, int index) {
            return listElements.elementAt(index);
        }
        public int indexOfList(ListField list, String p, int s) {
            return listElements.indexOf(p, s);
        }
        public int getPreferredWidth(ListField list) {
            return Graphics.getScreenWidth();
        }
        public void insert(String toInsert, int index) {
            listElements.addElement(toInsert);
        }
        public void erase() {
            listElements.removeAllElements();
        }
    } 
Developer
Posts: 17,012
Registered: ‎07-29-2008
My Device: Z10 LE, Z30, Passport
My Carrier: O2 Germany

Re: setRowHeight dramaticly slows down performance

set the rowheight outside of the drawListRow.
drawListRow is called for every single row of the field, if you change properties of the field it is possible that you trigger an invalidate which calls drawListRow etc.
In general the method should contain very less processing.
----------------------------------------------------------
feel free to press the like button on the right side to thank the user that helped you.
please mark posts as solved if you found a solution.
@SimonHain on twitter
Developer
Developer
Posts: 283
Registered: ‎07-22-2008
My Device: Not Specified

Re: setRowHeight dramaticly slows down performance

Since it is the same height for all rows, why don't you set it outside  drawListRow().

The way you are using it means that it is set with the refresh of each row. That could be the source of the problem.

Try to set it at the beginning when you create/populate  the list.

 

 

Rab

Developer
Posts: 15
Registered: ‎07-30-2009
My Device: Not Specified

Re: setRowHeight dramaticly slows down performance

[ Edited ]

How can I set it outside the drawlist, I'm new on this so some code sample could be fine Smiley Wink 

 

I tried This but I get "cannot find symbol"  on  setRowHeight(45);

 

    private static class ListCallback implements ListFieldCallback {

        private Vector listElements = new Vector();

         ListCallback(){

        

            setRowHeight(45);

        

        } 

 

  public void drawListRow(  ...........}

 

}

 

I populate the list with this code (where can i set row height here):

 

 myCallback = new ListCallback();

_keywordFilterField.setCallback(myCallback);


for (int i = 0; i < _nameList.size(); i++) {

                    String _name =  _nameList.getAt(i).toString();

                    myCallback.insert(_name, i);

                }  

Message Edited by RealCaracas on 07-30-2009 11:29 AM
Message Edited by RealCaracas on 07-30-2009 11:30 AM
Message Edited by RealCaracas on 07-30-2009 11:31 AM
Developer
Posts: 15
Registered: ‎07-30-2009
My Device: Not Specified

Re: setRowHeight dramaticly slows down performance

Well, is fixed, thanks for the answers... I know maybe is not the best solution but it works...

 

public void drawListRow(

        ListField list, Graphics g, int index, int y, int w) {

            

        if (list.getRowHeight() != 45) {

        list.setRowHeight(45);} 

        DRAW CODE....  

Regular Visitor
Posts: 1
Registered: ‎04-09-2010
My Device: 8100 pearl 4.5
My Carrier: Telefonica Ar

Re: setRowHeight dramaticly slows down performance

The right solution will be:

 

myCallback = new ListCallback();

_keywordFilterField.setCallback(myCallback);

_keywordFilterField.setRowHeight(40);//HERE IS THE KEY!



Yo do that once when creating the KeywordFilterField and you are done.

See you later!

Highlighted
Developer
Posts: 15
Registered: ‎07-30-2009
My Device: Not Specified

Re: setRowHeight dramaticly slows down performance

Almost One year later, but thanks...

It help me now that i'am coming back to the blackberry developing scene...