BlackBerryForums.com : Your Number One BlackBerry Community  
   

»Sponsored Links



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

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?
   
Reply With Quote
Sponsored Links
Please Login or Register to Remove these Advertisements!

  (#2 (permalink)) Old
pwaugh Offline
Knows Where the Search Button Is
 
Posts: 39
Join Date: Mar 2008
Model: 8820
PIN: N/A
Carrier: at&t
Default 07-23-2008, 12:25 AM

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

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.
   
Reply With Quote
  (#4 (permalink)) Old
pwaugh Offline
Knows Where the Search Button Is
 
Posts: 39
Join Date: Mar 2008
Model: 8820
PIN: N/A
Carrier: at&t
Default 07-23-2008, 01:15 AM

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.
   
Reply With Quote
  (#5 (permalink)) Old
VegetableBird Offline
New Member
 
Posts: 9
Join Date: Jul 2008
Model: 8100
PIN: N/A
Carrier: 8-)
Default 07-23-2008, 01:52 AM

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?
   
Reply With Quote
  (#6 (permalink)) Old
VegetableBird Offline
New Member
 
Posts: 9
Join Date: Jul 2008
Model: 8100
PIN: N/A
Carrier: 8-)
Default 07-23-2008, 02:32 AM

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.
   
Reply With Quote
Reply


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-2008 BlackBerryNews.com, BlackBerryFAQ.com, BlackBerryForums.com.
The names RIM © and BlackBerry © are registered Trademarks of Research In Motion Limited.
Powered by vBulletin® Version 3.6.8
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
SEO by vBSEO 3.0.1