我需要在Blackberry的按键事件中获取密钥的文本。当用户从键盘按下键以输入文本时,会发生这种情况。怎么可能?
答案 0 :(得分:1)
您可以通过覆盖keyChar来获取按下的关键文本
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));
}
}
答案 1 :(得分:1)
这有助于您:
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);
}
然后你可以得到 pressedKey 中的值(它是一个你必须先声明它的String变量)。