scroll change listener on blackberry

2019-08-28 00:29发布

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条回答
一夜七次
2楼-- · 2019-08-28 01:00

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.

查看更多
登录 后发表回答