BlackBerry Forums Support Community               

Closed Thread
 
LinkBack Thread Tools
Old 07-22-2008, 11:55 PM   #1 (permalink)
New Member
 
Join Date: Jul 2008
Model: 8100
PIN: N/A
Carrier: 8-)
Posts: 9
Post Thanks: 0
Thanked 0 Times in 0 Posts
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, 01:25 AM   #2 (permalink)
Knows Where the Search Button Is
 
Join Date: Mar 2008
Model: 8820
PIN: N/A
Carrier: at&t
Posts: 40
Post Thanks: 0
Thanked 0 Times in 0 Posts
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, 02:04 AM   #3 (permalink)
New Member
 
Join Date: Jul 2008
Model: 8100
PIN: N/A
Carrier: 8-)
Posts: 9
Post Thanks: 0
Thanked 0 Times in 0 Posts
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 02:06 AM.
Offline  
Old 07-23-2008, 02:15 AM   #4 (permalink)
Knows Where the Search Button Is
 
Join Date: Mar 2008
Model: 8820
PIN: N/A
Carrier: at&t
Posts: 40
Post Thanks: 0
Thanked 0 Times in 0 Posts
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, 02:52 AM   #5 (permalink)
New Member
 
Join Date: Jul 2008
Model: 8100
PIN: N/A
Carrier: 8-)
Posts: 9
Post Thanks: 0
Thanked 0 Times in 0 Posts
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, 03:32 AM   #6 (permalink)
New Member
 
Join Date: Jul 2008
Model: 8100
PIN: N/A
Carrier: 8-)
Posts: 9
Post Thanks: 0
Thanked 0 Times in 0 Posts
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


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.