问题
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