我有一个带有FOCUSABLE样式的LabelField和许多可聚焦的Field,并且我覆盖了LabelField的navigationMovement方法。问题是:代码永远不会进入navigationMovement的新实现,但焦点通常从LabelField移动到下一个Field而没有通过navigationMovement实现!
PS,我还使用调试器进行了测试,以确保它永远不会进入其实现。为什么会发生这种情况以及如何捕获 FOCUSABLE LabelField 的 navigationMovement 事件?
代码:
这是课程:
public abstract class FocusableLabelField extends LabelField {
public boolean isDownUnfocused = false;
public FocusableLabelField(String text) {
super(text, FOCUSABLE);
}
protected void drawFocus(Graphics graphics, boolean on) {
// DO NOTHING, FOCUS IS HANDLED IN PAINT
}
protected void paint(Graphics graphics) {
if(isDownUnfocused == true)
graphics.setColor(0xFFFFFF);
else {
if(isFocus())
graphics.setColor(0xFFFFFF);
else {
graphics.setColor(0x777777);
}
}
super.paint(graphics);
}
protected void onFocus(int direction) {
isDownUnfocused = false;
onFocusing();
super.onFocus(direction);
}
public abstract void onFocusing();
public void redraw() {
invalidate();
}
protected boolean navigationMovement(int dx, int dy, int status, int time) {
//TODO CHECK WHY IT'S NOT ENTERING HERE !
if(dy>0)
isDownUnfocused = true;
invalidate(); // IF REMOVED NO EFFECT WILL BE APPLIED
return super.navigationMovement(dx, dy, status, time);
}
}
这是我在屏幕中使用它的方式:
FocusableLabelField field = new FocusableLabelField("title") {
public void onFocusing() {
// some logic in the screen is done here ...
}
} ;