BlackBerry Forums Support Community
              

Closed Thread
 
Thread Tools
Old 07-22-2008, 10:55 PM   #1
VegetableBird
New Member
 
Join Date: Jul 2008
Model: 8100
PIN: N/A
Carrier: 8-)
Posts: 9
Question PhoneListener problem

Please Login to Remove!

I use PhoneListener to change the counter value of MainScreen like this:
Code:
public class _MainScreen extends MainScreen {
	public static int counter = 0;

	public _MainScreen() {
		super(DEFAULT_MENU | DEFAULT_CLOSE);
		setTitle("Call Reminder");
		MenuItem item = new MyMenuItem();
		addMenuItem(item);
	}
}

class MyMenuItem extends MenuItem {
	MyMenuItem() {
		super("add", 0, 100);
	}

	public void run() {
		_UiApplication.mainScreen.add(new LabelField(_MainScreen.counter + ""));
	}
}
Code:
public class _PhoneListener extends AbstractPhoneListener {
	public _PhoneListener() {
		Phone.addPhoneListener(this);
	}

	public void callInitiated(int callid) {
		_MainScreen.counter++;
		System.out.println(_MainScreen.counter);
	}
}
I make a call,the console print "1". But I press "add" menuItem the screen append "0".What's the problem?
Offline  
Old 07-23-2008, 12:25 AM   #2
pwaugh
Knows Where the Search Button Is
 
Join Date: Mar 2008
Model: 8820
PIN: N/A
Carrier: at&t
Posts: 40
Default

The reason I believe is because the menu item instantiates a "new" LabelField, and doesn't use the existing one.
Offline  
Old 07-23-2008, 01:04 AM   #3
VegetableBird
New Member
 
Join Date: Jul 2008
Model: 8100
PIN: N/A
Carrier: 8-)
Posts: 9
Default

It even don't work as follow:
Code:
class MyMenuItem extends MenuItem {
	MyMenuItem() {
		super("add", 0, 100);
	}

	public void run() {
		System.out.println(_MainScreen.counter);
	}
}
In phone listener, the console output "1". In main screen output "0".

Last edited by VegetableBird; 07-23-2008 at 01:06 AM..
Offline  
Old 07-23-2008, 01:15 AM   #4
pwaugh
Knows Where the Search Button Is
 
Join Date: Mar 2008
Model: 8820
PIN: N/A
Carrier: at&t
Posts: 40
Default

I don't see where you are adding counter to the mainscreen display, so it is just displaying "0" which is the default for an initialized int.

In other words, you need to add a LabelField to the mainscreen display in the screen constructor, then update it's .text value.
Offline  
Old 07-23-2008, 01:52 AM   #5
VegetableBird
New Member
 
Join Date: Jul 2008
Model: 8100
PIN: N/A
Carrier: 8-)
Posts: 9
Default

I'm sorry the problem still exist.
All i want is to catch the phone call in the phoneListener and transfer the information to the main screen.So far i haven't did it.I used to programming with j2me and not famlier with blackberry.Did i miss something?
Offline  
Old 07-23-2008, 02:32 AM   #6
VegetableBird
New Member
 
Join Date: Jul 2008
Model: 8100
PIN: N/A
Carrier: 8-)
Posts: 9
Default

I finally solve the problem by coding this:
Code:
public void callInitiated(int callid) {
		_UiApplication.mainScreen.add(new LabelField(info));
		UiApplication.getUiApplication().pushScreen(_UiApplication.mainScreen);
	}
The blackberry use stack to display screen and it won't update automatic as j2me.
Offline  
Closed Thread



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

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


iPhone 13 12 11 PRO MAX XR XS 8/7/6 Fast Charger USB Data Cable cord 10 feet/3M picture

iPhone 13 12 11 PRO MAX XR XS 8/7/6 Fast Charger USB Data Cable cord 10 feet/3M

$4.99



OEM iPhone 11 PRO X/XR XS MAX 8/7 PLUS Fast Charging USB Cable 10 Feet & 6 Feet  picture

OEM iPhone 11 PRO X/XR XS MAX 8/7 PLUS Fast Charging USB Cable 10 Feet & 6 Feet

$2.99



10 Foot/3M iPhone 12/11 PRO MAX X/10 XR XS 8/7 FAST Charging USB LONG Cable cord picture

10 Foot/3M iPhone 12/11 PRO MAX X/10 XR XS 8/7 FAST Charging USB LONG Cable cord

$4.98



10 Feet/3M For iPhone 13 12 11 PRO MAX MINI  X XR XS 8 7 Fast Charging USB Cable picture

10 Feet/3M For iPhone 13 12 11 PRO MAX MINI X XR XS 8 7 Fast Charging USB Cable

$5.00



Genuine A1417 OEM Battery Apple Macbook Pro 15 Retina A1398 Mid 2012 Early 2013 picture

Genuine A1417 OEM Battery Apple Macbook Pro 15 Retina A1398 Mid 2012 Early 2013

$37.90



OEM Battery for MacBook Pro 17

OEM Battery for MacBook Pro 17" A1309 A1297 Early 2009 Mid 2009 2010 MC226

$36.90







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