I am working on an Android Launcher application. I can host AppWidgets and display them on my View, which is derived from a LinearLayout. I can’t figure out how to set focus to the buttons within the widget (for example, the individual controls of the Power Control widget), as happens with the default launcher.
This is how I am assigning the focus to the AppWidgetHostView:
widgetView.setFocusable(true);
widgetView.setSelected(true);
widgetView.requestFocus(true);
The entire widget has the focus. I know this because the entire widget flashes if I click the dpad enter button.
How do I set the focus to one of the buttons within the widget? Do I need to enumerate the RemoteViews of the widget? If so, how?
I figured it out. (Thank you HierarchyViewer). If the AppWidgetHostView first child is a ViewGroup (e.g. LinearLayout), I remove focus from the widget and use the FocusFinder to assign focus to the first child.