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
Regular Contributor
Posts: 52
Registered: ‎06-24-2010
My Device: T-Mobile
My Carrier: 3

Re: key char shortcut doesn't work

This is the code I have override on the screen level

protected boolean keyChar(char key, int status, int time) {
		if (key == Characters.ENTER || key == 'p' ) {
			getApp().MunifPrev();
			invalidate();
				}
		else if (key == Characters.ENTER || key == 'g') {
			getApp().MunifGotos();
			invalidate();
		}	
		else if (key == Characters.ENTER || key == 'n') {
			getApp().MunifLanjut();
			invalidate();
		}
		else if (key == Characters.ENTER || key == 's') {
			getApp().MunifSearch();
			invalidate();
			}
		else if (key == Characters.ENTER || key == 'c' ) {
			getApp().ContentsMunif(-2);
			invalidate();
		}
		return false;
	}

 This code problem is when I press "enter" key, it will go only to 

getApp().MunifPrev();

 

in every situation.

 

When I remove all 

key == Characters.ENTER 

from the if clause, the "enter" than has been state in the button method is unknownable.

Please Help me to solve this Simon?

Developer
Posts: 16,997
Registered: ‎07-29-2008
My Device: Z10 LE, Z30, Passport
My Carrier: O2 Germany

Re: key char shortcut doesn't work

check for the focused field (getLeafFieldWithFocus()) when processing the enter key

----------------------------------------------------------
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
Regular Contributor
Posts: 52
Registered: ‎06-24-2010
My Device: T-Mobile
My Carrier: 3

Re: key char shortcut doesn't work

I'm sorry Simon, I'm still confusing, please help me how to check the focusField (getLeafFieldWithFocus() when processing enter key) ?
Regular Contributor
Posts: 52
Registered: ‎06-24-2010
My Device: T-Mobile
My Carrier: 3

Re: key char shortcut doesn't work

 
Developer
Posts: 16,997
Registered: ‎07-29-2008
My Device: Z10 LE, Z30, Passport
My Carrier: O2 Germany

Re: key char shortcut doesn't work

first you check for char == '\n' or Characters.ENTER.

then you check for field==button1 or field==button2 etc and determine the action to take.

----------------------------------------------------------
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
Regular Contributor
Posts: 52
Registered: ‎06-24-2010
My Device: T-Mobile
My Carrier: 3

Re: key char shortcut doesn't work

The "Enter" key is still not working

This is my code:

 

protected boolean keyChar(char key, int status, int time) {
		if(key == '\n' || key == Characters.ENTER)
		{
		if (field==colour) {
			getApp().MunifPrev();
			invalidate();
				}
		else if (field==colour1) {
			getApp().MunifGotos();
			invalidate();
		}	
		else if (field==colour2) {
			getApp().MunifLanjut();
			invalidate();
		}
		else if (field==colour3) {
			getApp().MunifSearch();
			invalidate();
			}
		else if (field==colour4) {
			getApp().ContentsMunif(-2);
			invalidate();
		}}
		
		else
		{
			if (key == 'p' ) {
				getApp().MunifPrev();
				invalidate();
					}
			else if (key == 'g') {
				getApp().MunifGotos();
				invalidate();
			}	
			else if (key == 'n') {
				getApp().MunifLanjut();
				invalidate();
			}
			else if (key == 's') {
				getApp().MunifSearch();
				invalidate();
				}
			else if (key == 'c' ) {
				getApp().ContentsMunif(-2);
				invalidate();
			}
		}return false;
	}

 Please help me, what is the mistake in my code above ?

 

Developer
Posts: 16,997
Registered: ‎07-29-2008
My Device: Z10 LE, Z30, Passport
My Carrier: O2 Germany

Re: key char shortcut doesn't work

i wondered why your code doesn't work, but it is still early here. then i spotted it.

you are checking field as a class variable. it should be, however, a variable on method level.

add this line as the first line in the method:

 

Field focusField = getLeafFieldWithFocus();

 now change all references of 'field' to 'focusField'.

 

----------------------------------------------------------
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
Regular Contributor
Posts: 52
Registered: ‎06-24-2010
My Device: T-Mobile
My Carrier: 3

Re: key char shortcut doesn't work

Thank you very much for your guide...
it's working now.
Smiley Wink GBU
Regular Contributor
Posts: 52
Registered: ‎06-24-2010
My Device: T-Mobile
My Carrier: 3

Re: key char shortcut doesn't work

The above problem has been solve.
But the problem emerge when I try to add the above class(ButtonMenu.java) which contains 5 button to other class.

The other class(ex:contents.java) add the ButtonMenu.java by this code :
...
BM = new ButtonMenu();
SetTitle(BM)
...

Because I want the char key (like s,c etc) can be accessed from the screen of contents.java,I have overriden the keyChar method on contents.java class,but it makes the 'enter' is not function or become unknown.

Please help me how to make this 'enter' can also be used in any other classes like contents.java?what code should I add to this class ?
Highlighted
Regular Contributor
Posts: 52
Registered: ‎06-24-2010
My Device: T-Mobile
My Carrier: 3

Re: key char shortcut doesn't work

[ Edited ]

Hello ,

Sorry for disturbing, I have just solve The solution, by adding the method overriden in each class, so the code is as follows :

 

protected boolean keyChar(char key, int status, int time) {
		
//		Field field = getLeafFieldWithFocus();
		//this.field1=field;
		try{
		if(key == '\n' || key == Characters.ENTER )
		{
			 fieldChangeNotify(0);
		}
		
		else
		{
			if (key == 'p' ) {
				getApp().MunifPrev();
				invalidate();
					}
			else if (key == 'g') {
				getApp().MunifGotos();
				invalidate();
			}	
			else if (key == 'n') {
				getApp().MunifLanjut();
				invalidate();
			}
			else if (key == 's') {
				getApp().MunifSearch();
				invalidate();
				}
			else if (key == 'c' ) {
				getApp().ContentsMunif(-2);
				invalidate();
			
		}}}
			catch (NullPointerException ex)
			{
				ex.toString();
			}
			return super.keyChar(key, status, time);
	}

 

 

 

Thanks

 

Best Regards,

Bagir