在黑莓上滚动更改监听器

时间:2011-07-30 13:11:38

标签: blackberry

我已经在链接下面发布了我的问题..

scroll change listener on blackberry

错误已解决。

但我需要在滚动后移动场中心位置。请提出任何想法......提前致谢... 滚动条中添加了多个字段... 滚动它的节目之后就这样了。

enter image description here

但是我需要像这样移动场中心位置。

enter image description here

请给出任何想法..

1 个答案:

答案 0 :(得分:3)

看起来你只需要一些标志来检测这是由用户发起的sroll事件,还是代码(以编程方式)。

如果以编程方式发起滚动事件,则设置一些布尔值,让我们将其称为ignoreScrollEvent,为true。像这样的Smth(伪代码):

private boolean ignoreScrollEvent = false;

public void scrollChanged(Manager manager, int newHorizontalScroll, 
         int newVerticalScroll) {
    if (!ignoreScrollEvent) {
         ignoreScrollEvent = true;
         // recalculate the newHorizontalScroll so the field in the focus 
         // gets in the middle
         horizontalScrollLayout.setHorizontalScroll(newHorizontalScroll);
         int fieldIndex = horizontalScrollLayout.getFieldAtLocation(
             newHorizontalScroll + customfieldwidth, 0
         );
         Field f = horizontalScrollLayout.getField(fieldIndex);
         f.setFocus();
         invalidate();
    } else {
         ignoreScrollEvent = false;
    }
}