How can I handle event in EditText Field?.
Example: when I enter some text in EditText then what I have to do generate custom layout?
below is my screen.Does any one have idea please tell me.
try this
EditField text=new EditField()
{
protected boolean keyChar(char key, int status, int time)
{
if((int)key==10)//10 is ASCII code of "Enter" key
{
add(new LabelField("New Field"));
}
return super.keyChar(key, status, time);
}
};
add(text);
after enter all data just click on enter then new label will appear on screen
Related
I am working on ListView section, in this, the user can search the content by name and directly move at the first element of List via pressing a keyboard button. Like, if you press button B from (right vertical manager) it will scroll the list and move focus to first record of B.
The code is working fine in simulator but it's not working on Touch device - I have BB 9380 Curve.
here is the code for :
LabelField a = new LabelField("A" , FOCUSABLE)
{
protected void paint(Graphics graphics)
{
graphics.setColor(0xC4C4C4);
super.paint(graphics);
}
protected boolean navigationClick(int status, int time)
{
//fieldChangeNotify(1);
injectKey(Characters.LATIN_CAPITAL_LETTER_A);
injectKey(Characters.LATIN_CAPITAL_LETTER_A);
return true;
}
};
private void injectKey(char key)
{
try
{
searchList.setFocus();
KeyEvent inject = new KeyEvent(KeyEvent.KEY_DOWN, key, 0);
inject.post();
/*inject.post();*/
} catch (Exception e) {
Log.d("In injectKey :: :: :: "+e.toString());
MessageScreen.msgDialog("In Inject Key "+e.toString());
}
}
Alternate Solution
I would recommend a different strategy for this. Instead of trying to simulate key press events, I would define one method that handles a keypress of a certain letter, or a touch click on that same letter's LabelField.
Source: blackberry.com
So, you can have code that handles key presses by using
protected boolean keyChar( char character, int status, int time )
{
// you might only want to do this for the FIRST letter entered,
// but it sounds like you already have the keypress handling
// the way you want it ...
if( CharacterUtilities.isLetter(character) )
{
selectLetter(character);
return true;
}
return super.keyChar( character, status, time );
}
and then also handle touch events:
LabelField a = new LabelField("A" , FOCUSABLE)
{
protected void paint(Graphics graphics)
{
graphics.setColor(0xC4C4C4);
super.paint(graphics);
}
protected boolean navigationClick(int status, int time)
{
char letter = getText().charAt(0);
selectLetter(letter);
return true;
}
};
then, simply define a method that takes in one character, and scrolls to the start of that part of the list:
private void selectLetter(char letter);
Key Injection
If you really, really want to simulate key presses, though, you might try changing the code so that it injects two events: key down, and then key up (you're currently injecting two key down events). This might be causing problems.
injectKey(Characters.LATIN_CAPITAL_LETTER_A, true);
injectKey(Characters.LATIN_CAPITAL_LETTER_A, false);
with
private void injectKey(char key, boolean down)
{
try
{
searchList.setFocus();
int event = down ? KeyEvent.KEY_DOWN : KeyEvent.KEY_UP;
KeyEvent inject = new KeyEvent(event, key, 0);
inject.post();
} catch (Exception e) { /** code removed for clarity **/
}
}
Additional Note
For UIs, I like to trigger events on the key up, or unclick events. I think this makes a better experience for the user. So, you could replace keyChar() with keyUp() and navigationClick() with navigationUnclick() if you want to do this.
Hi Friend's i want to show details when i click on this list field with image(location)means u take any lat long and show with it a image map.so please help me to solve this problem.
How is it possible please help me.
Thanks
on this link show the list field i am also create like this listfiled and when i click and show details with image map
How is it possible please help me.
Thanks
Here I am giving some example try this (assign index to each field in the list view). You can display your details in NewsScreen().
protected boolean navigationClick(int status, int time) {
int index;
System.out.println("CLICKED!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!");
index = this.getFieldWithFocusIndex();
UiApplication.getUiApplication().invokeLater(new Runnable(){
public void run() {
UiApplication.getUiApplication().pushScreen(new NewsScreen());
}
});
System.out.println("OUTPUTTTTTTTTTTTTTTT"+this.getFieldWithFocusIndex());
return true;
}
you could pass the image map String URI or bitmap byte to the other screen and show it
UiApplication.getUiApplication().invokeLater(new Runnable(){
public void run() {
UiApplication.getUiApplication().pushScreen(new NewsScreen(IMAGE MAP STRING));
}
});
I am new to BlackBerry and Java. I am trying to figure out but not getting any correct way to implemnt my task. I want to enter 16 digit password. So for that, I have four passwordEditField in HorizontalFieldManager, each passwordEditField allows max 4 digits. When I enter 4 digits in first leftmost passwordEditField, I want to set focus automatically to the following next passwordEditField without any keypress. I used,
passwordEditField = new PasswordEditField("","",4,0){
protected void onUnfocus()
{
this.setFocus(passwordEditField.getIndex()+1,0,0);
}
};
I tried moveFocus(), setFocus(), setCursorPosition() but not getting the focus on to next element. Is there any way i can impelement this task in blackberry.
passwordEditField.setChangeListener(new FieldChangeListener() {
public void fieldChanged(Field field, int context) {
String text = passwordEditField.getText().toString();
if (text.length() == 4) {
nextPasswordEditField.setFocus();
}
}
});
How to get selected row from blackberry objectlistfield, when user clicks on list item?
getSelectedIndex()
You will also have to set the setChangeListener() and implement the corresponding methods like fieldChanged() and keyDown()
have you read the documentation before asking ? Do you have a more specific question ?
public boolean navigationClick(int status, int time) {
Field focus = list.getLeafFieldWithFocus();
Dialog.alert("Focus String :: " + focus.getIndex());
if (focus instanceof ListField) {
ListField listField = (ListField)focus;
Dialog.alert("Selected Index"+listField.getSelectedIndex());
Dialog.alert("Selected List Value"+listField.getCallback().get(listField,
listField.getSelectedIndex()).toString());
}
return true;
}
I want my BlackBerry app to open a website when I focus on its name.
Can anybody tell me how to do that?
final LabelField label = new LabelField(url,LabelField.FOCUSABLE);
label.setFocusListener(new FocusChangeListener(){
public void focusChanged(Field field, int eventType) {
if(eventType == FOCUS_GAINED){
BrowserSession bSession = Browser.getDefaultSession();
bSession.displayPage(label.getText());
}
}
});
add(label);