Android MOGA controller menu handling

I’m developing the menu handling for the MOGA controller in my maze game MultiMaze. When the KEYCODE_DPAD_UP button is pressed I want to change focus to the button below the current button. I had some trouble finding a nextFocus method but I’ve now found the excellent getNextFocusDownId method.

So I’ll specify a button in the XML like this:

 
    <Button
        android:id="@+id/multiplayer_button"
        android:focusable="true"
        android:focusableInTouchMode="true"

        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_below="@+id/singleplayer_button"
        android:text="@string/main_menu_multiplayer_text"/>

Then when I detect a DPAD_UP signal I’ll focus the button above with the following code:

Button upButton = (Button)findViewById(multiplayerButton.getNextFocusUpId());
upButton.requestFocus();

Leave a Reply

Your email address will not be published. Required fields are marked *

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>