Muhammad Maqsoodur Rehman
Muhammad Maqsoodur Rehman

Reputation: 34257

How to get text through key press in Blackberry

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?

Upvotes: 1

Views: 377

Answers (2)

alishaik786
alishaik786

Reputation: 3726

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

Upvotes: 1

rfsk2010
rfsk2010

Reputation: 8611

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));
    } 
}   

Upvotes: 1

Related Questions