In about 1 every 10 attempts, the previous solution randomly failed to show the keyboard, although the text field was focused. This solution seems more reliable.