Well I have finally resolved this by developing my own home grown virtual keyboard. This should work until RIM fixes the bug with their virtual keyboard. In case anyone else is having the same problem, I have provide the code for it here:
public class MyVirtualKeyboard extends VerticalFieldManager
{
// 1---2---3
// 4---5---6
// 7---8---9
// .---0---x
private ButtonField[] numbers = new ButtonField[]
{
new ButtonField("1", ButtonField.CONSUME_CLICK),
new ButtonField("2", ButtonField.CONSUME_CLICK),
new ButtonField("3", ButtonField.CONSUME_CLICK),
new ButtonField("4", ButtonField.CONSUME_CLICK),
new ButtonField("5", ButtonField.CONSUME_CLICK),
new ButtonField("6", ButtonField.CONSUME_CLICK),
new ButtonField("7", ButtonField.CONSUME_CLICK),
new ButtonField("8", ButtonField.CONSUME_CLICK),
new ButtonField("9", ButtonField.CONSUME_CLICK),
new ButtonField(".", ButtonField.CONSUME_CLICK),
new ButtonField("0", ButtonField.CONSUME_CLICK),
new ButtonField("x", ButtonField.CONSUME_CLICK),
};
private ButtonField close = new ButtonField("Close",
ButtonField.CONSUME_CLICK);
private FieldChangeListener listener = new FieldChangeListener()
{
public void fieldChanged(Field f, int ctx)
{
if (ctx == FieldChangeListener.PROGRAMMATIC)
return;
String val = ((ButtonField) f).getLabel();
if (Character.isDigit(val.charAt(0)) || val.equals(".")
caller.setCharacter(val);
else if (val.equals("x")
caller.removeLastCharacter();
}
};
private Caller caller;
public MyVirtualKeyboard(Caller caller)
{
this.caller = caller;
// 4 rows of buttons will be displayed
int buttonIndex = 0;
for (int i = 0; i < 4; i++)
{
HorizontalFieldManager row = new HorizontalFieldManager();
for (int j = 0; j < 3; j++)
{
numbers[buttonIndex].setChangeListener(listener);
row.add(numbers[buttonIndex++]);
}
add(row);
}
close.setChangeListener(new FieldChangeListener()
{
public void fieldChanged(Field field, int ctx)
{
MyVirtualKeyboard.this.caller.closeMe();
}
});
add(close);
}
}
Here is the interface I created callled 'Caller':
public interface Caller
{
public void closeMe();
public void setCharacter(String character);
public void removeLastCharacter();
}
Here is how I invoke it (this code is in my MainScreen subclass, which is implementing FocusChangeListener and my call back interface Caller):
public void focusChanged(Field field, int ctx) {
currentlyEditing = null;
if (field != checkAmt && field != taxAmt)
return;
if (ctx == FocusChangeListener.FOCUS_GAINED)
{
currentlyEditing = (BasicEditField) field;
MyVirtualKeyboard keyboard = new MyVirtualKeyboard(this);
popup = new PopupScreen(keyboard);
getUiEngine().pushScreen(popup);
}
}
Here is the callback methods on the main screen class that take the input from the popup keyboard:
public void setCharacter(String character)
{
String currText = currentlyEditing.getText();
currText += character;
currentlyEditing.setText(currText);
}
public void removeLastCharacter()
{
String currText = currentlyEditing.getText();
if (currText.length() == 0)
return;
currentlyEditing.setText(currText.substring(0, currText.length() - 1));
}
public void closeMe()
{
getUiEngine().popScreen(popup);
}
Also, I have a menu item where if the user needs to display the keyboard, they can:
showKeyboard = new MenuItem("Show Keyboard", 3, 12) {
public void run()
{
MyVirtualKeyboard keyboard = new MyVirtualKeyboard(
MyScreen.this);
popup = new PopupScreen(keyboard);
getUiEngine().pushScreen(popup);
}
};
Here is what the popup virtual keyboard looks like:
Hopefully this will help someone else.
1 comment:
how to get which basic edit field effect
Post a Comment