问题
I need to get the text of the keys at the event of key press in Blackberry. This happens when the user presses a key from the the keypad in order to type text. How is that possible?
回答1:
you can get the pressed key text by overriding keyChar like this
public boolean keyChar(char key, int status, int time)
{
if (key == Characters.ESCAPE)
{
int result = Dialog.ask(Dialog.D_YES_NO,"Are you sure you want to exit?");
if (result == Dialog.YES) {
closePopup();
}
return(true);
}
else
if (key == Characters.ENTER)
{
processLocation();
return(true);
}
else
{
//the pressed key is key
return(super.keyChar(key,status,time));
}
}
回答2:
This helps you:
protected boolean keyChar(char ch, int status, int time)
{
if(ch == Characters.ESCAPE || ch == Characters.ENTER)
{
//Nothing to do;
}
else
{
pressedKey=pressedKey+ch;
}
return super.keyChar(ch, status, time);
}
Then you can get the values in pressedKey(it is a String variable you have to declare it first).
来源:https://stackoverflow.com/questions/8415113/how-to-get-text-through-key-press-in-blackberry