RVG*_*RVG 1 blackberry java-me
空格键在许多UI字段上都有默认操作:单击按钮字段,选择/取消选中复选框,在verticalfieldmanager上滚动.
我的屏幕有一个超过20行的列表字段.当用户点击空格键时,我希望列表字段滚动.
例如,BlackBerry默认日历应用,当我们点击空格键时,它会向下滚动.和BlackBerry默认文本消息,当我们点击空格键时,它将向下滚动.
这是默认属性吗?或者我是否需要编写空格键的代码?
您必须创建自定义键侦听器:
private class CustomKeyListener implements KeyListener {
public boolean keyChar(char key, int status, int time) {
if(key == Characters.SPACE){
//TODO handle key here
//WARNING: this code runs on event thread!
return true;
}
return false;
}
public boolean keyDown(int keycode, int time) {
return false;
}
public boolean keyRepeat(int keycode, int time) {
return false;
}
public boolean keyStatus(int keycode, int time) {
return false;
}
public boolean keyUp(int keycode, int time) {
return false;
}
}
Run Code Online (Sandbox Code Playgroud)
然后Mainscreen.addKeyListener使用键监听器的实例作为参数调用.
从那里,您可以使用该Manager.setVerticalScroll方法更改您的经理(主经理或嵌套的)滚动.如果要增加它,可以检索当前滚动调用Manager.getVerticalScroll,然后添加固定值.如果您VerticalFieldManager的屏幕没有嵌套,您可以尝试使用屏幕默认设置,您可以通过该设置进行呼叫Mainscreen.getMainManager.
更新:
对于列表字段,您可以调用ListField.getSelectedIndex和ListField.setSelectedIndex更改元素,但这不是平滑滚动.但是,如果将列表字段放在VerticalFieldManager中,则可以如上所述更改管理器滚动.
| 归档时间: |
|
| 查看次数: |
245 次 |
| 最近记录: |