How to get text through key press in Blackberry

2019-08-11 14:31发布

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?

2条回答
2楼-- · 2019-08-11 14:43

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).

查看更多
戒情不戒烟
3楼-- · 2019-08-11 14:54

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));
    } 
}   
查看更多
登录 后发表回答