0

I would like to control arrow key events in android. I am testing the app in Samsung I5500 phone. The app consists of tabs. I was successful to capture the events using listeners.

@Override
public boolean onKeyUp(int keyCode, KeyEvent event) {
    Log.i(TAG_NAME, "key event: " + keyCode);
    if(keyCode == KeyEvent.KEYCODE_DPAD_CENTER) {
        Log.i(TAG_NAME, "Directional centre pad pressed");
    }
}

For instance, an activity in the third tab contains a listview of 3 items

Item A
Item B
Item C

I navigate to third tab using right arrow and clicked down arrow to select one of the above items. Clicking DPAD_CENTER key triggers ItemClick listener attached to the listView. Everything is fine until now. However, after that, current tab focus is moved to home (tab 0). The adapter which tries to render UIfails to load since it is in a different tab. Eventually it crashes down.

Has anyone experienced this before? I searched in the internet. I didn't find anything worth enough.

Renjith
  • 3,457
  • 5
  • 46
  • 67

1 Answers1

0

If you are looking at using the DPAD keys to find focus on different UI items, then you should design your XML layout to know which view to focus. See http://developer.android.com/reference/android/view/View.html#FocusHandling

You will need to specify nextFocusUp/nextFocusDown/nextFocusRight/nextFocusLeft for each of your element.

For ListViews and Tabs there is a default implementation which exists, and for the very same reason you can scroll down and up the list view.

Following these guidelines will make your app more responsive to DPAD events and provide seasmless user interaction (when using AIR mouse/dpad controllers, etc)

Abhishek Nandi
  • 4,265
  • 1
  • 30
  • 43