I’m trying to create an interface for a launcher app that can be traversed using only a d-pad. My layout is hierarchical, with each top level item having a list of options. To navigate to this second list, the user would either be able to press the item, or press right.
The problem is, that because of the way Android determines the correct view to focus based on location, the cursor jumps to the incorrect item (what ever is directly next to the cursor). Refer to figure 1 below; if the user were to press right, Dev Tools would be highlighted instead of API Demos.
The same goes for going back to the left. In figure 2, when the user presses right, Music would be selected instead of Applications.

So far I’ve tried the following to manually select the correct view:
appListView.setOnFocusChangeListener(new OnFocusChangeListener() {
@Override
public void onFocusChange(View v, boolean hasFocus) {
if(hasFocus) {
((ListView) v).getChildAt(0).requestFocus();
} else {
findViewById(R.id.apps_button).requestFocus();
}
}
});
This fails (I assume) because the dpad action has already fired a requestFocus, and I’ve verified that I’m getting the right child view, that the child view is focusable, and that requestFocus() returns false;
What can I do to make this work as expected? Thanks in advance 🙂
EDIT 1:
I also just tried setting the application buttons NextFocusRightId to the first item of the list view (which is set programatically by the list adapter @ position 0); nothing.
EDIT 2:
NextFocus___Id is working on these buttons too, since Videos’ up focus is Settings, which works fine…
I finally figured it out!
Manually focusing list items is best done through the ListView itself. It works cleanly going to the right by extending the ListView class with the following change:
and to the left by just setting the NextFocusLeft of the listview (not the items) as such: