1

在我正在构建的应用程序中,我有选项卡和每个选项卡的列表。我想要的行为是当我按下左/右导航键时,选定的选项卡会改变。当我按下向上/向下导航键时,列表将更改选择索引。

我使用 LWUIT GUI builder 来生成StateMachine/StateMachineBase类。

我整天都在努力解决这个问题。请帮忙。

4

2 回答 2

1

你为什么要把你的生活复杂化?只需keyReleased在您的类中使用方法实现。做一个测试:

if (display.getGameAction(keyCode) == Display.GAME_LEFT || display.getGameAction(keyCode) == Display.GAME_RIGHT)
{
    if (tab.getSelectedIndex == 0)
        tab.setSelectedIndex(1);
    else
        tab.setSelectedIndex(0);
}
else if (display.getGameAction(keyCode) == Display.GAME_UP || display.getGameAction(keyCode) == Display.GAME_DOWN)
{
    if (list.hasFocus())
        super.keyReleased(keyCode);
}
于 2011-11-16T11:24:16.500 回答
1

Pheromix 的回答是正确的,但他没有考虑到UIBuilder. 要覆盖 UIBuilder 中的表单创建覆盖方法:

protected Component createComponentInstance(String componentType, Class cls) {
    if(cls == com.sun.lwuit.Form.class) {
        return new MyFormSubclass();
    }
    return super.createComponentInstance(componentType, cls);
}

有一个选项可以覆盖选项卡选择行为,但要获得最准确的行为,这可能是最好的方法。

于 2011-11-20T07:36:00.480 回答