一个解决办法
这不是一个根本解决的方法:写一个新的class,继承ListView,覆盖onFocusChanged。
@Override protected void onFocusChanged(boolean gainFocus, int direction, Rect previouslyFocusedRect) { super.onFocusChanged(gainFocus, direction, previouslyFocusedRect); if (gainFocus && previouslyFocusedRect != null) { final ListAdapter adapter = getAdapter(); final int count = adapter.getCount(); switch (direction) { case FOCUS_DOWN: for (int i = 0; i < count; i++) { if (!adapter.isEnabled(i)) { continue; } setSelection(i); break; } break; case FOCUS_UP: for (int i = count-1; i>=0; i--) { if (!adapter.isEnabled(i)) { continue; } setSelection(i); break; } break; default: break; } } }
在这里,我只处理了FOCUS_DOWN和FOCUS_UP。由于不能访问mFirstPosition,处理也做了简化:焦点从上方移下来时选择第一个能选择的,从下方移上来时选择最后一个能选择的。