BlackBerry Forums Support Community               

Closed Thread
 
LinkBack Thread Tools
Old 03-17-2009, 06:59 PM   #1 (permalink)
New Member
 
Join Date: Jan 2009
Model: 7100T
PIN: N/A
Carrier: Rogers
Posts: 5
Post Thanks: 0
Thanked 0 Times in 0 Posts
Default VerticalFieldManager hides part of field when scrolling

Please Login to Remove!

Hello,



I have a main VFM and a CustomFieldManager, where the CustomFieldManager (CFM) extends a VFM and has a height and width of 50. Creating 5 CFM's and adding them to the main VFM allows me to scroll and select each CFM but when i get past the height of the screen, (so at the 5th CFM), only part of it is displayed. Meaning that only a few pixels are displayed instead of the entire 50. I have to keep scrolling for the entire 50 to be displayed. However i know this field is in focus as i have the focused fields colored. So basically i'm trying to get the entire field to show as i scroll down. I guess I didn't explain this too well so here's the code. This is my first time posting so sorry if the format pasting the code gets messed!


Here's the code for the CustomFieldManager:

Code:
public class ThumbnailFieldManager extends VerticalFieldManager implements IntegerConstants {
	
	private int numRows;
	private int style;
	private int managerHeight;
	private int columns = 1;
	
	public ThumbnailFieldManager(int _numRows, long _style) {
		//super(Manager.VERTICAL_SCROLL);
		//style = _style;
		super();
		numRows = _numRows;		
		managerHeight = (getPreferredHeight() * numRows);
	}
	
	protected void sublayout(int width, int height) {
	
		Field field;
		int x = 0;
		int y = 0;
		
		for (int i = 0; i < getFieldCount(); i++) {

			field = getField(i);
		
			layoutChild(field, width, getPreferredHeight());
			
			long fieldStyle = field.getStyle();
			int fieldXOffset = 0;
			long fieldHalign = fieldStyle & Field.FIELD_HALIGN_MASK;
			
			if (fieldHalign == Field.FIELD_RIGHT) {
				fieldXOffset = THUMBNAIL_WIDTH - field.getWidth();
			}
			else if (fieldHalign == Field.FIELD_HCENTER) {
				fieldXOffset = ((THUMBNAIL_WIDTH-field.getWidth())/2); 
			}
			
			int fieldYOffset = 0;
			long fieldValign = fieldStyle & Field.FIELD_VALIGN_MASK;
			
			if (fieldValign == field.FIELD_BOTTOM) {
				fieldYOffset = HEADLINE_HEIGHT - field.getHeight();
			}
			else if (fieldValign == Field.FIELD_VCENTER) {
				fieldYOffset = ((HEADLINE_HEIGHT/2) - ((field.getHeight())/2));
			}
					
			setPositionChild(field, x+fieldXOffset, y+fieldYOffset);

			y += getPreferredHeight();
			
		}
		
		setExtent(THUMBNAIL_WIDTH, managerHeight);
	}
	
	
	public int getPreferredWidth() {
		return THUMBNAIL_WIDTH;
	}
	
	public int getPreferredHeight() {
		return HEADLINE_HEIGHT;
	}
	
    protected void onUnfocus() {
    	super.onUnfocus();
        invalidate();
    }

    public boolean isFocusable() {
    	return true;
    }
	
    protected void drawFocus(Graphics graphics, boolean on) {
        // Don't draw the default focus
    }
    

    protected void onFocus(int direction) {
        super.onFocus(direction);
        invalidate();
    }
	
	public void paintBackground( Graphics g ) {
        g.clear();
        int color = g.getColor();
        g.setColor( Color.BLACK );
        g.fillRect( 0, 0, THUMBNAIL_WIDTH, managerHeight);
        g.setColor( color );
    }
	
	public void paint(Graphics g)
    {
		
		if (this.isFocus()) {
			g.setBackgroundColor(Color.BLUE);
			g.clear();
		} else {
			g.setBackgroundColor(Color.ORANGE);
			g.clear();
		}
		super.paint(g);
    }
}
And here's the code for the screen that implements a VFM and adds the CFM:

Code:
class HeadlinesScreen extends MainScreen implements IntegerConstants {
	
	private ThumbnailFieldManager thumbnails;
	private VerticalFieldManager vfm;
	
	HeadlinesScreen() {
		super();
		VerticalFieldManager vfm = new VerticalFieldManager(Manager.VERTICAL_SCROLL | Field.FOCUSABLE);
		vfm.add(new LabelField("testXX"));
		
		LabelField lf[] = {new LabelField("1", Field.FIELD_VCENTER | Field.FIELD_HCENTER), new LabelField("2"), new LabelField("3", Field.FOCUSABLE | Field.FIELD_VCENTER | Field.FIELD_HCENTER), new LabelField("4"), new LabelField("5testtttt")};
				
		for(int i = 0; i < 5; i++) {
			thumbnails = new ThumbnailFieldManager(1, 0);
			thumbnails.add(lf[i]);
			vfm.add(thumbnails);
			vfm.add(new SeparatorField());
		}
		
		vfm.add(new LabelField("testYY"));
		add(vfm);
		
	}

}
What am i doing wrong??



Thanks in advance,

Andrew
Offline  
Closed Thread


Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On





Copyright 2004-2014 BlackBerryForums.com.
The names RIM and BlackBerry are registered Trademarks of BlackBerry Inc.