Reliably showing the Android keyboard for ViewGroups too
The other day, I was browsing through the Android blog world (make sure to check out https://blog.danlew.net/ ), and found this really awesome blog post from the developers over at Square about reliably displaying the Android keyboard, which is controlled by a rather difficult API. After trying out their code, however, I realized that it did not work for my purpose which was to focus a SearchView after clicking a button. The bug was really strange, because while we had called requestFocus() on the SearchView , when we queried it for isFocused , it would return false ! Turns out, after a lot of struggling, I found that requestFocus() actually may give focus to one of the descendants of the View instead. SearchView is actually a ViewGroup , so focus was actually given to a TextView that was a child of the SearchView . After learning about this, the fix was easy: Instead of only directly checking the SearchView for isFocused , do a recursive check on the focusedChild of the Searc...