Вопрос

In the application I'm building I have Tabs and a list in for each Tab. the behavior I want is when I press the Left/Right Nav Key the selected Tab will change. when I press the Up/Down Nav Key the List will change selection index.

I used LWUIT GUI builder to generate StateMachine/StateMachineBase class.

I've been trying to fix this all day. please help.

Это было полезно?

Решение

Pheromix's answer is correct but he didn't account for the UIBuilder. To override the Form creation in the UIBuilder override the method:

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

There is an option to override the Tab selection behavior but to get the most accurate behavior this might be the best approach.

Другие советы

Why do you complicate your life ? Just use keyReleased method implementation in your class. Make a test :

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);
}
Лицензировано под: CC-BY-SA с атрибуция
Не связан с StackOverflow
scroll top