scroll change listener on blackberry

独自空忆成欢 提交于 2020-01-17 08:11:24

问题


When I execute the following code on a simulator it throws stackoverflow error.

I think the error came for, Each newhorizontalScroll value when I scroll.

How to avoid it or how to calculate the final horizontal scroll value?

int customfiledwidth = Display.getWidth()/3;


HorizontalFieldManager horizontalScrollLayout = new HorizontalFieldManager(HorizontalFieldManager.HORIZONTAL_SCROLL)
horizontalScrollLayout.setScrollListener(this);

// i add number of customfield on horizontalscrolllayout.....

public void scrollChanged(Manager manager, int newHorizontalScroll,int newVerticalScroll) 
{
    {

        horizontalScrollLayout.setHorizontalScroll(newHorizontalScroll);
        int fieldIndex =horizontalScrollLayout.getFieldAtLocation(newHorizontalScroll+customfieldwidth,0);
        Field f = horizontalScrollLayout.getField(fieldIndex);
        f.setFocus();
        invalidate();
        }}
    }

回答1:


You're getting into an infinite loop pretty much by calling setHorizontalScroll() on the same Field that you are listening to its scroll. I would remove this line and see if your code works.



来源:https://stackoverflow.com/questions/6870614/scroll-change-listener-on-blackberry

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!