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
New Developer
vezikon
Posts: 3
Registered: ‎12-31-2012
My Device: Bold 9700
My Carrier: Vodafone
Accepted Solution

Blackberry doesn't scroll back to the top of the screen only to the middle !

[ Edited ]

have an app which is displaying a news screen with app banner and title + image + details (RichTextField) and an Ad banner on the bottom of the screen so once I scroll down to read the details I can't get back to the top .. it stops on the middle of the screen as you see in these pictures ..I don't know why .. it works perfectly when you use the touch on touch screen devices

 

before scrolling after scrolling back up

 

and here's the code I've used for this screen 

 

public class DetailsScreen_en extends MainScreen {

	AppManager appManager;
	private Detailsbean_en bean;
	private AppManager manager;
	private BitmapField bitmapField;
	private LabelField titleField;
	private LabelField dateField;
	private RichTextField articleField;
	private Bitmap bitmap;
	private BitmapField bar;
	private HorizontalFieldManager hfm;
	Adsbean[] adsBean;
	BitmapField ad;
	VerticalFieldManager otherStuff;
	VerticalFieldManager vvv;
	Timer time;
	TimerTask task;
	private HorizontalFieldManager admanager;
	private int adCounter = 0;
	private boolean status;
	private int tour;

	public DetailsScreen_en(boolean status, int tour) {
		appManager = AppManager.getInstance();
		adsBean = appManager.getAdsBean();
		Locale.setDefault(Locale.get(Locale.LOCALE_en));
		// ScreenOne.showLoadingScreen();
		this.status = status;
		this.tour = tour;
		XYEdges padding = new XYEdges(10, 10, 10, 10);
		HTMLParser parser = new HTMLParser();

		vvv = new VerticalFieldManager(VerticalFieldManager.VERTICAL_SCROLL
				| Field.FOCUSABLE) {
			protected void sublayout(int maxWidth, int maxHeight) {
				// TODO Auto-generated method stub
				super.sublayout(maxWidth, maxHeight);
				setExtent(maxWidth, Display.getHeight() - ad.getHeight());
			}
		};
		hfm = new HorizontalFieldManager();
		bar = new BitmapField(DesignSizes.FanClubBar(), Field.FIELD_HCENTER
				| Field.NON_FOCUSABLE | Field.READONLY);
		hfm.add(bar);
		vvv.add(hfm);
		hfm = new HorizontalFieldManager();
		manager = AppManager.getInstance();
		bean = manager.getBean_en();
		// System.out.println("DATE: "+ bean.getNewsDate() );

		// another try ...
		Date _date;
		Calendar _cal = Calendar.getInstance();
		_cal.set(Calendar.YEAR,
				Integer.parseInt(bean.getNewsDate().substring(0, 4)));
		_cal.set(Calendar.MONTH,
				Integer.parseInt(bean.getNewsDate().substring(5, 7)) - 1);
		_cal.set(Calendar.DAY_OF_MONTH,
				Integer.parseInt(bean.getNewsDate().substring(8, 10)));

		_date = _cal.getTime();

		DateFormat dff = new SimpleDateFormat("dd MMMM yyyy");
		String datedatedate = dff.formatLocal(_date.getTime());
		dateField = new LabelField(datedatedate);
		dateField.setPadding(padding);
		titleField = new LabelField(bean.getNewsTitle(), Field.FIELD_LEFT) {
			protected void paint(Graphics graphics) {
				// TODO Auto-generated method stub
				graphics.setColor(Color.ORANGE);
				super.paint(graphics);
			}

		};
		titleField.setPadding(padding);
		Font font = Font.getDefault().derive(Font.BOLD, 9, Ui.UNITS_pt);
		titleField.setFont(font);
		bitmapField = new BitmapField(DesignSizes.newsIsLoading(),
				Field.FIELD_HCENTER);
		bitmapField.setPadding(padding);
		setBitmap(bean.getImgUrl());

		articleField = new RichTextField(parser.clean(bean.getNewsArticle()),
				RichTextField.USE_TEXT_WIDTH | RichTextField.TEXT_ALIGN_LEFT
						| RichTextField.READONLY);
		// bitmap field for the add bitmap
		ad = new BitmapField(DesignSizes.adBanner(), Field.FIELD_TRAILING
				| Field.FIELD_HCENTER);
		// horizontal field manager to set the bitmapfield away from the
		// scrollable screen .. as its required to be only
		// on the bottom of the screen !

		admanager = new HorizontalFieldManager(
				VerticalFieldManager.NO_VERTICAL_SCROLL
						| VerticalFieldManager.NO_VERTICAL_SCROLLBAR
						| Field.FIELD_HALIGN_MASK);

		// the other stuff title bar + action bar + itemRow + button more
		otherStuff = new VerticalFieldManager(
				VerticalFieldManager.VERTICAL_SCROLL) {
			protected void sublayout(int maxWidth, int maxHeight) {
				// TODO Auto-generated method stub
				super.sublayout(maxWidth, maxHeight);
				setExtent(maxWidth, Display.getHeight() - ad.getHeight());
			}
		};
		admanager.add(ad);
		// font for the article
		Font artFont = Font.getDefault().derive(Font.PLAIN, 6, Ui.UNITS_pt);
		articleField.setPadding(padding);
		articleField.setFont(artFont);
		vvv.add(dateField);
		vvv.add(titleField);
		vvv.add(bitmapField);
		vvv.add(articleField);
		add(vvv);
		add(admanager);

		switch (Display.getWidth()) {
		case 320:
			getAd(adsBean[adCounter].getBlackberry320());
			break;
		case 360:
			getAd(adsBean[adCounter].getBlackberry360());
			break;
		case 480:
			getAd(adsBean[adCounter].getBlackberry480());
			break;
		case 640:
			getAd(adsBean[adCounter].getBlackberry640());
			break;
		}

		
	}

	private void setBitmap(final String url) {

		// TODO Auto-generated method stub\\

		UiApplication.getUiApplication().invokeLater(new Runnable() {

			public void run() {
				// TODO Auto-generated method stub
				final DownLoadImage dope = new DownLoadImage(url);
				bitmap = dope.getImage();
				Bitmap resized_bitmap = bitmap;
				Bitmap tempbitmap = new Bitmap(Display.getWidth() - 20,
						(int) ((Display.getWidth() - 20) * 0.458));
				tempbitmap.createAlpha(Bitmap.TRUE_WHITE);
				resized_bitmap.scaleInto(tempbitmap, Bitmap.FILTER_LANCZOS);
				bitmap = tempbitmap;
				bitmapField.setBitmap(bitmap);

			}
		});
	}

	protected boolean keyDown(int keycode, int time) {
		int key = Keypad.key(keycode);
		if (key == Characters.ESCAPE) {
			try{
				this.time.cancel();
			}catch(Exception e){
				
			}
			UiApplication.getUiApplication().pushScreen(
					new NewsScreen_en(status, tour));

			return true;
		}
		return super.keyDown(keycode, time);
	}

	// =============================================================================================
		// for getting the ads ...
		// =============================================================================================
		private void loadAD(int timer) {
			System.out.println("Timer start! ");

				time = new Timer();
				task = new TimerTask() {

					public void run() {
						time.cancel();
						switch (Display.getWidth()) {
						case 320:
							getAd(adsBean[adCounter].getBlackberry320());
							break;
						case 360:
							getAd(adsBean[adCounter].getBlackberry360());
							break;
						case 480:
							getAd(adsBean[adCounter].getBlackberry480());
							break;
						case 640:
							getAd(adsBean[adCounter].getBlackberry640());
							break;
						}
						System.out.println("tik tik tik");
					}
				};
				time.schedule(task, timer * 1000);
				
		}

		private void getAd(final String url) {

			UiApplication.getUiApplication().invokeLater(new Runnable() {

				public void run() {
					// TODO Auto-generated method stub
					final DownLoadImage dope = new DownLoadImage(url);
					Bitmap bitmap = dope.getImage();
					ad.setBitmap(bitmap);
				}
			});
			
			
			//for saving more memo
			switch(Integer.parseInt(adsBean[adCounter].getAdDuration())){
			case 0:
				//
				break;
			default:
				System.out.println("loading ad! ");
				adCounter++ ;

				if(adCounter == adsBean.length || adCounter > adsBean.length){
				adCounter = 0;
				}
				loadAD(Integer.parseInt(adsBean[adCounter].getAdDuration()));
				break;
			}


			

//	
		}

		// =============================================================================================
		// =============================================================================================

	protected void makeMenu(Menu menu, int instance) {
		// TODO Auto-generated method stub
		menu.deleteAll();
		menu.add(new MenuItem("Language", 120, 10) {
			public void run() {
				// TODO Auto-generated method stub
				super.run();
				UiApplication.getUiApplication().pushScreen(new SplashScreen());
			}

		});
		menu.add(new MenuItem("About", 120, 10) {
			public void run() {
				// TODO Auto-generated method stub
				super.run();
				UiApplication.getUiApplication().pushScreen(
						new AboutScreen_en());
			}
		});
		menu.addSeparator();
	}
}

 

please help me 

 

Please use plain text.
Developer
simon_hain
Posts: 16,113
Registered: ‎07-29-2008
My Device: Z10 LE, Z30, Passport
My Carrier: O2 Germany

Re: Blackberry doesn't scroll back to the top of the screen only to the middle !

scrolling takes into account focusable fields only.
you can add a NullField at the top to allow scrolling to it.
----------------------------------------------------------
feel free to press the like button on the right side to thank the user that helped you.
please mark posts as solved if you found a solution.
@SimonHain on twitter
Please use plain text.
New Developer
vezikon
Posts: 3
Registered: ‎12-31-2012
My Device: Bold 9700
My Carrier: Vodafone

Re: Blackberry doesn't scroll back to the top of the screen only to the middle !

I added null fields between all fields and it worked ... Thanks alot 

Please use plain text.