我有一个LabelField whith样式FOCUSABLE和许多可关注的Field s之后,我覆盖了navigationMovement的LabelField方法。
navigationMovement的新实现,但焦点通常从LabelField移到下一个Field而不经过{{3}实施!
PS,我还使用调试器测试,以确保它永远不会进入其实现。
为什么会发生这种情况以及如何捕获FOCUSABLE LabelField的navigationMovement事件?
CODE:
这是班级:
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 ...
}
} ;
答案 0 :(得分:0)
我刚刚在5.0 8900模拟器和7.1 9900模拟器上的应用程序中运行了完全代码,而我确实看到您调用的navigationMovement()
。但是,我并不是100%确定它是在你想要的时候被调用的。
我不确切知道你要做什么,但看看上面的代码,看起来你只是想为焦点颜色添加自定义绘图。是吗?
如果是这样,我甚至不知道为什么你甚至需要覆盖navigationMovement()
。为什么不使用这样的代码:
public abstract class FocusableLabelField extends LabelField {
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) {
int oldColor = graphics.getColor();
if(isFocus())
graphics.setColor(0xFFFFFF);
else {
graphics.setColor(0x777777);
}
super.paint(graphics);
graphics.setColor(oldColor);
}
protected void onFocus(int direction) {
onFocusing();
invalidate();
super.onFocus(direction);
}
protected void onUnfocus() {
invalidate();
super.onUnfocus();
}
public abstract void onFocusing();
}