views:

28

answers:

1

I use tabs in my Android application and one of my tabs contains a listview. I'm noticing some weird behavior when I override isEnabled in my list's adapter and then try to use the D-pad to move up and down through the list and to my tabs.

If the 0th item of the list is enabled, then everything works as expected - I can move down through the list, and then up again and once I reach the top of the list, pressing up moves focus to my tab.

However, if the 0th item is DISABLED (isEnabled in my adapter returns false), then when I press up while position 1 is focused, the focus gets stuck. It doesn't move up to the tab as I would have expected and instead stays on position 1 of the list.

Any ideas?

A: 

override the onKeyDown(...) method. check for the up key/up roller ball. If all the above list items are disabled, set the focus to the tab.

NOTE: you may have to do the same thing coming down, I'm not sure.

@Override
public boolean onKeyDown(int keyCode, KeyEvent event) {

    switch(keyCode){
    case KeyEvent.KEYCODE_DPAD_UP:
        if(/*all the above list items are disabled*/)
        {
            //focus on tab
        }
    }
    return super.onKeyDown(keyCode, event);
}
mtmurdock