场外黑莓的TouchEvent触发fieldChanged [英] BlackBerry touchEvent outside Field triggers fieldChanged
问题描述
我有在那里,如果我美元的字段是触发具有焦点领域中的 fieldChanged()
事件之外p $ PSS /触摸一个问题。
I am having a problem where if i press/touch outside of a field the fieldChanged()
event is triggered for the field that has focus.
有关的布局我的 MainScreen
是pretty向前伸直,像这样:
The layout for my MainScreen
is pretty straight forward, something like so:
public class myMainScreen extends MainScreen implements FieldChangeListener{
public myMainScreen(){
CustomFM1 fm1 = new CustomFM1();
CustomFM2 fm2 = new CustomFM2();
add(fm1);
add(fm2);
}
}
如果我preSS任 FieldManager
它工作正常内部按钮/场。问题是,当我美元空的空间P $ PSS。所以,如果我是里面空的空间preSS在 FM2
和字段
在 FM1
有重点,其fieldchanged事件将被触发。
If i press a button/field inside of either FieldManager
it works fine. The problem is when i press on empty space. So if i were to press inside empty space in fm2
and a Field
inside fm1
had focus, its fieldchanged event would be triggered.
目前,我的补救办法是赶的TouchEvent
并把它传递到相应的 FieldManager
。在的TouchEvent
我的 CustomFM
然后将处理让该领域,并呼吁fieldChanged,如果一个领域其实一直pressed
At the moment, my remedy is to catch the touchEvent
and pass it down to the appropriate FieldManager
. The touchEvent
for my CustomFM
would then handle getting the field and calling fieldChanged, if a field has actually been pressed
因此,在 myMainScreen
的TouchEvent如下:
So in myMainScreen
touchEvent looks like:
protected boolean touchEvent(TouchEvent message){
int index = this.getFieldAtLocation(message.getX(1), message.getY(1));
switch(index){
case 0:
fm1.touchEvent(message);
break;
case 1:
fm2.touchEvent(message);
break;
}
return true;
}
和我的的TouchEvent
我CustomFM2是。 OFFSET
是FM2的顶部y位置相对于屏幕。
And my touchEvent
for my CustomFM2 is.
OFFSET
is the top y position of fm2, in relation to the screen.
protected boolean touchEvent(TouchEvent message){
switch(message.getEvent()){
...
case TouchEvent.UP:
int index = this.getFieldAtLocation(message.getGlobalX(1), message.getGlobalY(1) - OFFSET);
if(index != -1){
Field field = getField(index);
field.getChangeListener().fieldChanged(field, 0);
}
break;
}
return true;
}
我想知道的是,如果有一个更简单的解决方案呢?我这么想吗?
What I'm wondering is that if there is an easier solution to this? Am i missing something?
推荐答案
刚刚有同样的问题。主要的问题是, navigationClick
和 trackwheelClick
如果触摸事件未在消耗被称为的TouchEvent
。
Just had the same issue. The main problem is that navigationClick
and trackwheelClick
are called if the touch event is not consumed in touchEvent
.
解决方法是调用 fieldChangeNotify
在 *点击
方法的仅如果点击是由非触摸事件触发。触摸事件给出的0状态,因此您可以检查该如下:
The solution is to call fieldChangeNotify
within the *Click
methods only if the click was triggered by a non-touch event. Touch events are given a status of 0 so you can check for that as follows:
protected boolean navigationClick( int status, int time ){
if (status != 0) fieldChangeNotify(0);
return true;
}
protected boolean trackwheelClick( int status, int time ){
if (status != 0) fieldChangeNotify(0);
return true;
}
此方法意味着不需要跟踪触摸事件是否是场的范围内。
This method means you don't need to track whether the touch event was within the bounds of the field.
这篇关于场外黑莓的TouchEvent触发fieldChanged的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!