我有一个AbsoluteFieldManager,它在水平行中包含多个Fields,切换焦点工作正常。现在我需要在与上面左侧字段相同的水平位置添加另一个Field。这样做时,我无法专注于第一个领域。屏幕应如下所示:
________________________
| ____ ____ ____ |
| |_f1_| |_f2_| |_f3_| |
| ____ |
| |_f4_| | with f4 added here, f1 isn't focusable, once it has
|______________________| lost focus.
如果您有任何想法如何解决这个问题,我会感到满意。到目前为止,这是我的代码:
TestScreen:
import net.rim.device.api.system.Display;
import net.rim.device.api.ui.container.AbsoluteFieldManager;
import net.rim.device.api.ui.container.MainScreen;
public class TestScreen extends MainScreen {
int screenY = Display.getWidth();
int screenX = Display.getHeight();
public TestScreen() {
AbsoluteFieldManager manager = new AbsoluteFieldManager();
TestField f1 = new TestField(50, 50, true);
TestField f2 = new TestField(50, 50, true);
TestField f3 = new TestField(50, 50, true);
TestField f4 = new TestField(50, 50, true);
TestField f5 = new TestField(50, 50, false);
manager.add(f1, 0, 0);
manager.add(f2, 60, 0);
manager.add(f3, 120, 0);
manager.add(f4, 180, 0);
// this works fine:
// manager.add(f5, 1, 80);
// this not:
manager.add(f5, 0, 80);
add(manager);
}
}
TestField:
import net.rim.device.api.ui.Field;
import net.rim.device.api.ui.Graphics;
public class TestField extends Field {
boolean isFocusable;
int width, height;
int bgColorUnfocused, bgColorFocused;
public TestField(int width, int height, boolean isFocusable){
this.width=width;
this.height=height;
this.isFocusable=isFocusable;
bgColorUnfocused= 0xC0C0C0;
bgColorFocused = 0x3956F7;
}
protected void layout(int w, int h) {
setExtent(width, height);
}
public boolean isFocusable() {
return isFocusable;
}
protected void paint(Graphics g) {
g.setColor(isFocus() ? bgColorFocused : bgColorUnfocused);
g.fillRect(0, 0, width, height);
}
}
TestApp:
import net.rim.device.api.ui.UiApplication;
public class TestApp extends UiApplication{
TestScreen screen = new TestScreen();
public static void main(String args[]){
TestApp app = new TestApp();
app.enterEventDispatcher();
}
public TestApp(){
pushScreen(screen);
}
}
答案 0 :(得分:3)
由于AbsoluteFieldManager并不确定您放置物品的位置,因此在使用拨轮时它不知道发送焦点的顺序。如果你想对AFM进行管理,那么你可以根据它的位置和预期的移动位置来指定获得焦点的人。