How to get text through key press in Blackberry

China☆狼群 提交于 2019-12-13 01:15:47

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!