Welcome!

Welcome to the official BlackBerry Support Community Forums.

This is your resource to discuss support topics with your peers, and learn from each other.

inside custom component

Java Development

Reply
Contributor
Posts: 19
Registered: ‎09-24-2011
My Device: blackberry 8520
My Carrier: MTN
Accepted Solution

visual scroll of my vertical manager

hello everybody,

 

i use a vertical manager that contains 7 custom focusable horizontal managers(HM) that contain 3 fields each. when i run my application on small screen devices like the 9300, i can only see 4 (HM) at a time and need to scroll down to see others. everything is fine expect the fact that the vertical manager scroll only when i reach the last HM. that means when i jump to the 5th HM, i can't see it because the manager does not scroll. it scroll only when i reach the last one and i continue to go down. i want the scroll to be synchronised with the focus so that i can see the field with the focus.

 

 

thank you for your help

 

NOTE: the vertical manager  i use is the standard one that 's why i didn't add the code. i use it with vertcalscroll and vertical scroll bar style

 

 

 

Developer
Posts: 19,636
Registered: ‎07-14-2008
My Device: Not Specified

Re: visual scroll of my vertical manager

That is unusual and not what I would expect.  I can see two potential issues that might cause this:

 

1) One of the enclosing Managers has determined that it is bigger than it actually is.  So are you adding the VFM that is not scrolling how you want to a standard MainScreen?

 

2) The VFM is not seeing the correct sizes for the HFMs.  Do you use setExtent for the HFMs?

 

Possibly the easiest way to resolve this problem is remove your tailoring, bit at a time, until it starts working correctly.  I would focus on the layout() and sublayout() code as the most likely area that is causing this error. 

Contributor
Posts: 19
Registered: ‎09-24-2011
My Device: blackberry 8520
My Carrier: MTN

Re: visual scroll of my vertical manager

[ Edited ]
super(NO_VERTICAL_SCROLL | USE_ALL_HEIGHT);

 this is the style of my main screen

 

layout() and sublayout() of my VFM or HFM?

Contributor
Posts: 19
Registered: ‎09-24-2011
My Device: blackberry 8520
My Carrier: MTN

Re: visual scroll of my vertical manager

package mypackage;


import net.rim.device.api.ui.Color;
import net.rim.device.api.ui.FieldChangeListener;
import net.rim.device.api.ui.Graphics;
import net.rim.device.api.ui.Keypad;
import net.rim.device.api.ui.Manager;
import net.rim.device.api.ui.TouchEvent;
import net.rim.device.api.ui.XYRect;

import net.rim.device.api.system.*;


public class MyMainManager extends Manager {

	public MyMainManager(long style)
	{
		super(style);
	}
	
			
	// TODO Auto-generated constructor stub}

	protected void sublayout(int width, int height) {
		// TODO Auto-generated method stub

		int basic=getField(2).getPreferredWidth();
		int basic0=getField(0).getPreferredHeight();
		int basic3=getField(2).getPreferredHeight();
		int basic1=getField(1).getPreferredHeight();
		
		
		if(basic0>basic1)
		{basic1=basic0;
		  if(basic0>basic3)
		  {
			  basic3=basic0;
		  }else
		  {
			  basic0=basic3;
			  basic1=basic3;
		  }
		}
		else
		{
			if(basic1>basic3)
			  {
				  basic3=basic1;
			  }else
			  {
				  basic0=basic3;
				  basic1=basic3;
			  }
			basic0=basic1;
		}
		int basic4=basic0-(basic0/4);
		
		setPositionChild(
	             getField(0), 
	             (basic/4), 
	             ((basic4 - getField(0).getPreferredHeight())/2));
	         layoutChild(
	             getField(0), 
	             getField(0).getPreferredWidth(), 
	             getField(0).getPreferredHeight());

	         setPositionChild(
	             getField(1), 
	             Display.getWidth() - (Display.getWidth()- ((basic * 2 )-(basic/2))), 
	             ((basic4 - getField(1).getPreferredHeight())/2));
	         layoutChild(
	             getField(1), 
	             getField(1).getPreferredWidth(), 
	             getField(1).getPreferredHeight());    

	         setPositionChild(
	             getField(2), 
	             Display.getWidth() - (basic), 
	             ((basic4 - getField(2).getPreferredHeight())/2));
	         layoutChild(
	             getField(2), 
	             getField(2).getPreferredWidth(), 
	             getField(2).getPreferredHeight());    

	         
	         
	         setExtent(width, basic4);
	   
	}
	
	// to make the field focusable
	public boolean isFocusable() {
		return true;
		}
	
	protected void subpaint(Graphics graphics) {
		if (isFocus()) {
			graphics.setColor(5263440);
			graphics.fillRect(0, 0, getWidth(), getHeight());
			graphics.setGlobalAlpha(255);
		
		
		}
		super.subpaint(graphics);
		}
	
	protected void onFocus(int direction) {
		super.onFocus(direction);
		invalidate();
		}
		protected void onUnfocus() {
		super.onUnfocus();
		invalidate();
		}

	
	//to desactivate the field
	protected void drawFocus(Graphics graphics, boolean on) {
		
	}
		
protected boolean navigationClick(int status, int time) 
{
    fieldChangeNotify(0);
    return true;
}
protected boolean keyChar(char character, int status, int time) {
	if (character == Keypad.KEY_ENTER) {
	fieldChangeNotify(0);
	return true;
	}
	return super.keyChar(character, status, time);
	}   
protected boolean touchEvent(TouchEvent message) {
	if (TouchEvent.CLICK == message.getEvent()) {
		fieldChangeNotify(0);
		return true;		
	}
	return super.touchEvent(message);
}

}

 this is my HFM. as you can see, I use setExtent

Developer
Posts: 2,268
Registered: ‎07-08-2009
My Device: various
My Carrier: various

Re: visual scroll of my vertical manager

One of the obvious things that your sublayout lacks is setVirtualExtent. Your extent is the visual size of the manager. Virtual extent is the full size of the scrollable area.

Your extent should not exceed the passed width and height values, so using your basic4 as height is not correct - take the minimum of basic4 and height parameter.

Virtual extent can have an almost infinite size in the direction(s) of scrolling.The most practical use, however, is to calculate the total width/height of managed fields and use those dimensions in setVirtualExtent.

 

Another problem is that your sublayout allows for exactly three managed fields. Unless you know exactly what fields will those be and how many, you'd better make it more generic.

 

I will not comment on your position calculations - again, it might be right for your custom screen. However, your layoutChild calls are at least suspicious. Preferred width and height are extremely unreliable as indicators of how much the field will actually need unless, again, the fields themselves are highly customized and utilize those in their layout calculations. Normally you tell the field how much it can have and then, after layoutChild, ask it how much room it actually grabbed using getWidth and getHeight.

 

Try some built-in manager such as VerticalFieldManager and make it work somehow (might be ugly, but functional). If you need to space out the fields, use setMargin on them. Once you see something reasonable, go back and implement your custom layout.

----------------------------------------------------------
please click 'Accept Solution' on posts that provide the solution to the question you've posted. Don't say "Thanks", press 'Like' button instead!
Developer
Posts: 19,636
Registered: ‎07-14-2008
My Device: Not Specified

Re: visual scroll of my vertical manager

[ Edited ]

Edit:

 

Comment removed, arkadyz contribution is much more relevant. 

Contributor
Posts: 19
Registered: ‎09-24-2011
My Device: blackberry 8520
My Carrier: MTN

Re: visual scroll of my vertical manager

[ Edited ]

you are right arkadyz, the problem is my custom horizontal manager. let me follow your instruction to see if it works. 

thank you for your help guys

Contributor
Posts: 19
Registered: ‎09-24-2011
My Device: blackberry 8520
My Carrier: MTN

Re: visual scroll of my vertical manager

[ Edited ]

I resolved the problem by setting focusable one of the fields my custom manager take. It works 100% fine

I guess there is much better way to do it.

 

thank you guys for your help.