黑莓在笨拙的布局中延迟加载

发布于 2024-12-13 14:11:46 字数 4789 浏览 0 评论 0原文

我通过扩展 VerticalFieldManager 使用自定义列表字段,对于行,我使用另一个扩展 Manager 的 CustoRowManager。 CustomRowManager 有 2 个 TextField 和一个 BitmapField 。此列表是针对实时 xml feed 实现的。为了加载位图字段,我显示占位符,然后将其替换为来自后台线程的实际图像。我无法弄清楚应该如何用位图字段替换占位符。使用 invalidate() 是一种选择,但我应该在哪个元素上执行它。

public class CustomList extends VerticalFieldManager{
private int totalHeight = 0;
private int screenHeight = 0;
private int scrollPosition = 0;

protected void sublayout(int width, int height)
{
    width = 480;
    height = 230;
            super.sublayout(width,height);
    setExtent(width, height);
}   

protected boolean navigationClick(int status, int time)
{
    int index;
    System.out.println("CLICKED!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!");
    if ((status & KeypadListener.STATUS_FOUR_WAY) == KeypadListener.STATUS_FOUR_WAY) 
        {           
        index = this.getFieldWithFocusIndex();
        UiApplication.getUiApplication().pushScreen(new TopNewsScreen(_vec, index));
        }
    return true;
}   

Bitmap _bmp = null;
BitmapField _bmF = null;
Object _Obj = null;
TopNews _topNews = null;
String _headStr = null, _metaStr = null;
CustTextField _headNews = null, _metaData = null;
CustomRow _custRow = null;
Vector _vec;

public CustomList(Vector _vec,long _property)
{
    super(_property);
    this._vec = new Vector();
    this._vec = _vec;

    int _size = _vec.size();
    int i ;

    for(i = 0; i <_size; i++)
    {   
        _headStr = new String();
        _metaStr = new String();
        _bmp = Bitmap.getBitmapResource("img/1.jpg");
        _bmF = new BitmapField(_bmp);

        _topNews = (TopNews)_vec.elementAt(i);
        _headStr = _topNews.getHeadline();
        _metaStr = _topNews.getMetaData();

        int _newsLeng = _headStr.length(), alert = 0;

        if(_newsLeng <= 35)
        {
            alert = 0;
        }else if(_newsLeng>35&&_newsLeng<=70)
        {
            alert = 1;
        }else {
            alert = 2;
            _headStr = this.truncate(_headStr,70);

        }
        _custRow = new CustomRow(alert);

        _headNews = new CustTextField(_headStr,25,0x05235b,TextField.NON_FOCUSABLE);
        _metaData = new CustTextField(_metaStr,15,0x666666,TextField.NON_FOCUSABLE);

        _custRow.add(_headNews);
        _custRow.add(_metaData);
        _custRow.add(_bmF);

        super.add(_custRow);


    }
}



String truncate(String value, int length)
{
      if (value != null && value.length() > length)
        value = value.substring(0, length);
      return value;
}
}

class CustomRow extends Manager implements FocusChangeListener{

private int  _headLeng;
private NullField _focus = null;

CustomRow(int _headLeng)
{
    super(Manager.FOCUSABLE|
            Manager.NO_HORIZONTAL_SCROLL
            |Manager.NO_VERTICAL_SCROLL);

    this._headLeng = _headLeng;
    _focus = new NullField(NullField.FOCUSABLE);
    _focus.setFocusListener(CustomRow.this);
    this.add(_focus);

}

protected void sublayout(int width, int height) 
{
    if(_headLeng==0)
    {
    layoutChild(getField(0),0,0);  
    setPositionChild(getField(0),0 , 0);

    layoutChild(getField(1),360,20);  
    setPositionChild(getField(1),10 , 10);

    layoutChild(getField(2),300, 20);
    setPositionChild(getField(2), 10, 65);

    layoutChild(getField(3),90,65);
    setPositionChild(getField(3), 380, 10);

    }else
    {
    /*  layoutChild(getField(0),0,0);  
        setPositionChild(getField(0),0 , 0);

        layoutChild(getField(1),360,20);  
        setPositionChild(getField(1),10 , 10);

        layoutChild(getField(2),300, 20);   
        setPositionChild(getField(2), 10, 50);

        layoutChild(getField(3),90,65);
        setPositionChild(getField(3), 380, 10);     */
        layoutChild(getField(0),0,0);  
        setPositionChild(getField(0),0 , 0);

        layoutChild(getField(1),360,20);  
        setPositionChild(getField(1),10 , 10);

        layoutChild(getField(2),300, 20);
        setPositionChild(getField(2), 10, 65);

        layoutChild(getField(3),90,65);
        setPositionChild(getField(3), 380, 10);

    }

    height = 80;
    width = 480;  
    setExtent(width, height);
}
protected void paint(Graphics graphics)
{
    graphics.setColor(Color.GRAY);
    graphics.drawLine(10, 79, Display.getWidth()-10, 79);
    super.paint(graphics);
}

public void focusChanged(Field field, int eventType) {
    // TODO Auto-generated method stub
    this.getManager().invalidate();
}



protected void paintBackground(Graphics g) {
      int prevBg = g.getBackgroundColor();
      if (_focus.isFocus()) {
        g.setBackgroundColor(Color.LIGHTBLUE);
      } else {
        g.setBackgroundColor(Color.WHITE);
      }
      g.clear();
      g.setBackgroundColor(prevBg);
    }
}

I am using a customlistfield by extending VerticalFieldManager, and for the row I am usingf another CustoRowManager that extends Manager. The CustomRowManager has 2 TextField and a BitmapField . This list is implemented for a live xml feed. For loading the bitmapfield I am displaying placeholders which is then replaced by the actual image from background thread. I am not able to figure out how I should replace place holders with the bitmapfield. using invalidate() is one option, but on which element I should perform it.

public class CustomList extends VerticalFieldManager{
private int totalHeight = 0;
private int screenHeight = 0;
private int scrollPosition = 0;

protected void sublayout(int width, int height)
{
    width = 480;
    height = 230;
            super.sublayout(width,height);
    setExtent(width, height);
}   

protected boolean navigationClick(int status, int time)
{
    int index;
    System.out.println("CLICKED!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!");
    if ((status & KeypadListener.STATUS_FOUR_WAY) == KeypadListener.STATUS_FOUR_WAY) 
        {           
        index = this.getFieldWithFocusIndex();
        UiApplication.getUiApplication().pushScreen(new TopNewsScreen(_vec, index));
        }
    return true;
}   

Bitmap _bmp = null;
BitmapField _bmF = null;
Object _Obj = null;
TopNews _topNews = null;
String _headStr = null, _metaStr = null;
CustTextField _headNews = null, _metaData = null;
CustomRow _custRow = null;
Vector _vec;

public CustomList(Vector _vec,long _property)
{
    super(_property);
    this._vec = new Vector();
    this._vec = _vec;

    int _size = _vec.size();
    int i ;

    for(i = 0; i <_size; i++)
    {   
        _headStr = new String();
        _metaStr = new String();
        _bmp = Bitmap.getBitmapResource("img/1.jpg");
        _bmF = new BitmapField(_bmp);

        _topNews = (TopNews)_vec.elementAt(i);
        _headStr = _topNews.getHeadline();
        _metaStr = _topNews.getMetaData();

        int _newsLeng = _headStr.length(), alert = 0;

        if(_newsLeng <= 35)
        {
            alert = 0;
        }else if(_newsLeng>35&&_newsLeng<=70)
        {
            alert = 1;
        }else {
            alert = 2;
            _headStr = this.truncate(_headStr,70);

        }
        _custRow = new CustomRow(alert);

        _headNews = new CustTextField(_headStr,25,0x05235b,TextField.NON_FOCUSABLE);
        _metaData = new CustTextField(_metaStr,15,0x666666,TextField.NON_FOCUSABLE);

        _custRow.add(_headNews);
        _custRow.add(_metaData);
        _custRow.add(_bmF);

        super.add(_custRow);


    }
}



String truncate(String value, int length)
{
      if (value != null && value.length() > length)
        value = value.substring(0, length);
      return value;
}
}

class CustomRow extends Manager implements FocusChangeListener{

private int  _headLeng;
private NullField _focus = null;

CustomRow(int _headLeng)
{
    super(Manager.FOCUSABLE|
            Manager.NO_HORIZONTAL_SCROLL
            |Manager.NO_VERTICAL_SCROLL);

    this._headLeng = _headLeng;
    _focus = new NullField(NullField.FOCUSABLE);
    _focus.setFocusListener(CustomRow.this);
    this.add(_focus);

}

protected void sublayout(int width, int height) 
{
    if(_headLeng==0)
    {
    layoutChild(getField(0),0,0);  
    setPositionChild(getField(0),0 , 0);

    layoutChild(getField(1),360,20);  
    setPositionChild(getField(1),10 , 10);

    layoutChild(getField(2),300, 20);
    setPositionChild(getField(2), 10, 65);

    layoutChild(getField(3),90,65);
    setPositionChild(getField(3), 380, 10);

    }else
    {
    /*  layoutChild(getField(0),0,0);  
        setPositionChild(getField(0),0 , 0);

        layoutChild(getField(1),360,20);  
        setPositionChild(getField(1),10 , 10);

        layoutChild(getField(2),300, 20);   
        setPositionChild(getField(2), 10, 50);

        layoutChild(getField(3),90,65);
        setPositionChild(getField(3), 380, 10);     */
        layoutChild(getField(0),0,0);  
        setPositionChild(getField(0),0 , 0);

        layoutChild(getField(1),360,20);  
        setPositionChild(getField(1),10 , 10);

        layoutChild(getField(2),300, 20);
        setPositionChild(getField(2), 10, 65);

        layoutChild(getField(3),90,65);
        setPositionChild(getField(3), 380, 10);

    }

    height = 80;
    width = 480;  
    setExtent(width, height);
}
protected void paint(Graphics graphics)
{
    graphics.setColor(Color.GRAY);
    graphics.drawLine(10, 79, Display.getWidth()-10, 79);
    super.paint(graphics);
}

public void focusChanged(Field field, int eventType) {
    // TODO Auto-generated method stub
    this.getManager().invalidate();
}



protected void paintBackground(Graphics g) {
      int prevBg = g.getBackgroundColor();
      if (_focus.isFocus()) {
        g.setBackgroundColor(Color.LIGHTBLUE);
      } else {
        g.setBackgroundColor(Color.WHITE);
      }
      g.clear();
      g.setBackgroundColor(prevBg);
    }
}

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

夏尔 2024-12-20 14:11:46

下面的链接有问题的答案,我应该将名称更改为 Blackberry 延迟加载。

http://supportforums.blackberry.com/t5/Java -开发/Clumsy-layout-invalidate/mp/1398763

the below link has answer for the question, I should change the name to Blackberry lazyloading.

http://supportforums.blackberry.com/t5/Java-Development/Clumsy-layout-invalidate/m-p/1398763

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文