0

I am creating a custom text field for my application by extending RichTextField, I am passing the text I need to the constructor and adding that object where ever it is needed. My application is a news paper application has around 20-30 size list in few pages and description pages and some pages has 100-200 list, can this method of creating text slow down my application? Is there any better other method for creating customtext??

public class CustTextField extends RichTextField{

private String _text;
private FontFamily _fontFamily1;
private int _size, _color;
private Font _headFont = null;

public CustTextField(String _text, int _size,int _color, long _property)
{
    super(_text, _property);
    FontFamily _fontFamily1;
    this._color = _color;
    try{
        _fontFamily1 = FontFamily.forName("aerial");
    } catch(ClassNotFoundException e) {
            _fontFamily1 = Font.getDefault().getFontFamily();
    }
     _headFont = _fontFamily1.getFont(Font.PLAIN,_size);

     super.setFont(_headFont);
}

protected void paint(net.rim.device.api.ui.Graphics g) {
    g.setColor(_color);
    super.paint(g);
}

}

I am using the above code for the customtextfield.

varunrao321
  • 925
  • 2
  • 10
  • 18
  • Are you calling invalidate() inside paint() ? .This usually slows down the code. Also all lengthy operations must be done in a different thread than event thread. Are you accident-prone doing lengthy operations in the event thread? – rfsk2010 Nov 15 '11 at 16:12
  • What I think Rihan is trying to say is - how can we help you without seeing your code??? :) – Tamar Nov 15 '11 at 18:08
  • @Tamar, thanks for your reply, I edited the above post, sorry for not posting the code before.. – varunrao321 Nov 16 '11 at 05:45
  • @Rihan, I am not calling invalidate inside paint, but I have posted the code above..am I doing any mistake? – varunrao321 Nov 16 '11 at 05:46
  • 4
    @Newbie Having looked at the code, I cant find anything unusual which might slow down your code. Why dont you try using a Labelfield instead of customfield just to see if the code performs well. If it does, we know its the customfield which is causing the issue. If not,we know its drawing about 100-200 list is the cause of the performance lag. – rfsk2010 Nov 16 '11 at 09:57
  • thanks a lot for your reply Rihan, sure I will try the same with labelfield.. – varunrao321 Nov 16 '11 at 13:30
  • @Rihan have one more query, would you like to share some of your knowledge ? – varunrao321 Nov 17 '11 at 10:40
  • @Rihan I have a doubt if the database connection I am performing is slowing down the app, can I post that code here? – varunrao321 Nov 18 '11 at 06:30

1 Answers1

0

If you need to extend a class to do what you need to do then you have to do that. Extending a class will have a performance penalty, but it shouldn't be noticiable if the rest of you coding practices are efficient. RIM provides a good set of recommendations for efficient coding on BlackBerry platform here.

Richard
  • 8,920
  • 2
  • 18
  • 24